What is "Capture namespace name"?

62 views Asked by At

I have this line of code somewhere:

Sys.Attribute? testClassAttribute = Helpers.TryGetAttributeByFullName( type,
        "Microsoft.VisualStudio.TestTools.UnitTesting.TestClassAttribute" );

When I selected the string literal and I pressed the key for ReSharper suggestions, the top suggestion was "Capture namespace name".

enter image description here

I have been using ReSharper for years, and I have never seen this suggestion before.

When I chose this option, nothing seemed to happen.

So I went to Google, and searched for resharper "capture namespace name". Google said that there were no results, and reverted to searching without the quotes, with predictably useless results. As a matter of fact, Google said the same thing when I searched for "capture namespace name" alone.

Apparently there is no documentation anywhere for this ReSharper feature. Does anyone know what it actually does?

2

There are 2 answers

1
Dmitry Matveev On

It appears that you're not using the most recent version of ReSharper. The action you mentioned was recently renamed to "Use 'nameof' expression to capture name of entity." This makes its intent clearer as it replaces the entity hard-coded in the string literal with the corresponding nameof expression.

The reason nothing happened in your case might be due to a bug in an older version. Therefore, I recommend upgrading to the latest version and check if it works. If this doesn't resolve your issue, please don't hesitate to contact ReSharper support.

0
Niklas On

its a feature that allows your class namespace to match the directory its contained in, essentially "capturing" the namespace.

for example if your project is named MyApp and it contains a folder called Classes and you have a class within the classes folder called Tools.cs, the namespace should be MyApp.Classes.

this is basically 'adjust namespaces'. depending on your rider version and context, it will be named differently. this is what i understand as i have two pcs and see one in each.