Вопрос

So, in my ASP.NET C# code base I have possibly hundreds of bits of code like this:

Response.Redirect("something.aspx?Error=" + ex.Message);

I want to automatically add an argument to all of these method calls to add 'true' as the second parameter to this method, like this:

Response.Redirect("sometihng.aspx?Error=" + ex.Message, true);

I have Visual Studio 2010 and the latest version of Resharper at my disposal.

I tried using the 'Search with Pattern' feature in Resharper (VS menu -> ReSharper -> Find -> Search with Pattern) to see if this would automatically refactor my codebase, but I'm not sure exactly how or if it works. Here's what I tried:

SearchWithPattern

On the right-hand side, I created an 'Argument' placeholder called 'anyString', in the hope that this would find and replace all invocations of Response.Redirect that have a string in the first argument, but this found no matches in my code-base.

Any ideas on how I might solve this without resorting to manually changing all references?

Это было полезно?

Решение

As per the Jetbrains Resharper documentation on 'Searching a Code with Pattern':

Pay attention, that when you use a placeholder, its name should be enclosed with dollar signs (use the syntax $xx$, where xx represents placeholder name),whereas when you create a new placeholder, you should omit these special symbols.

Therefore, I was on the right track. Also for the placeholder I just need '$anyString$' and it will find all invocations of the method, even if they are made up multiple string objects (e.g. string literals and string objects). So this is how it would look:

SearchWithPatternSolution

The 'anyString' placeholder pattern was created by performing the following steps:

1) Click 'Add Placeholder' -> Argument

2) Give it a name, e.g. 'anyString'

For my case, I also checked the 'Limit minimal number of arguments' and selected 1, and I also checked the 'Maximal' box and set that to 1 also.

The 'Save' button is also useful if you intend on reusing the pattern again.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top