From time to time I need to change the use of one method call to another.
eg. I have 100 method calls like this:
Helper.GetIntFromData(packetData.Skip(offset).Take(length).ToArray());
which need to be changed to
Helper.GetIntFromData(packetData, offset, length);
This is relatively easy to solve with regex. But what if whitespace comes into play (sometimes)?
Helper.GetIntFromData(packetData .Skip( offset ) .Take( length ) .ToArray() );
Still executed with regex, but now it's an unreadable mess of optional tokens for scrolling.
OK, but what if the parameters are not always simple identifiers, but arbitrary expressions ?
Helper.GetIntFromData(obj.GetData(true).Skip( 7 + GetOffset( item.GetData() ) ) .Take( length1 / length2 ).ToArray());
Here regular expressions really break.
My question is:
Can this be done today? (so that you remain operational, that is, without regular expression)
Is there a VS extension or a standalone tool that can handle searching and replacing C # code at a higher (semantic) level?
Something to let me search (I think):
Helper.GetIntFromData($expr1.Skip($expr2).Take($expr3).ToArray())
and replace with
Helper.GetIntFromData($1, $2, $3)
Is there such a tool for C #? (I suppose it could be built around Roslin.)
c # regex visual-studio roslyn
Cristi diaconescu
source share