How to define search pattern

I have converted a VB solution to C# with the help of SharpDevelop. Now i want to replace a number of MsgBox() calls by MessageBox.Show(). Old and new code looks like this:

2012-07-28_15h14_19.png
I want to replace occurrences of the first line by the second line. When i try to generate the pattern via "Find similar code" i get an "pattern is ambigous" error.

2012-07-28_15h20_13.png
When i try to define a pattern myself i get an error "Unexpected token".

2012-07-28_15h24_21.png
When i change the language from C# to VB.NET the error disappears, but R# won't find any occurence of the pattern.

Can anyone tell me how to solve this? There are are around 100 occurrences of this and i don't want to change them manually.

[Edit]
Additionally i tried to fix another error in VB. There are method calls with optional parameters lilke this:

FillVarRec(mvPar, enumTEMPoPar.gkiTEMPoEnde, "TEMPo_ENDE", "", , Datentypen.[String], , , "Bemerkung")

and i want to change to use named parameters like this:

FillVarRec(mvPar, enumTEMPoPar.gkiTEMPoEnde, "TEMPo_ENDE", "", Typ:=Datentypen.[String], Desc:="Bemerkung")

Nevertheless how i define the pattern R# always did'nt find any occurrence (i tried to define the parameters as argument, expression and identifier). Is Search with pattern broken???

Regards
Klaus

2 comments
Comment actions Permalink

Hello Klaus
     I couldn't reproduce this behavior on a small converted solution. Could you please attach a small solution that would help us to investigate this problem? Thank you!

Andrey Serebryansky

Software Developer

JetBrains, Inc

http://www.jetbrains.com

"Develop with pleasure!"

0
Comment actions Permalink

Hello Andrey,

i did some further investigations on the problem and i think i finally found the reason. The problem is the VB syntax for optional parameters in method calls. To omit an optional parameter i can put an additional "," in the parameter list like this:

MsgBox("My Message", , "My Title")

to show a message box with the default Ok button. If i use this syntax in C# i get a "Missing Argument" error.  If i use named parameters like this:

Interaction.MsgBox("My Message", Title: "MyTitle");

search with pattern works fine.

My second problem has the same reason.

My dilemma is now that i want to correct exactly this error via pattern search and replace because there are several hundrets occurrences in the code.

I have attached a small solution which reproduces the problem both in C# and VB. If you mark the first Interaction.MsgBox in the C# project and try to use "Find similar code" you will get an error. The second line works well. If you try to find the FillVarRec in the VB solution via "Find similar code" nothing happens. If you change from "Find" to "Replace" R# says "Nothing found...".

Regards
Klaus



Attachment(s):
ResharperProblems.7z.zip
0

Please sign in to leave a comment.