Previous | Index | Next 

[HOWTO] Skipping one or more methods when applying the PreProcess or PostProcess pragmas

Note: this article only applies to conversions to VB.NET

It is possible to apply the PreProcess or PostProcess pragmas to an entire file or project, except a well defined list of methods. There are two techniques to achieve this result.

In the first approach, you specify the name of all the methods to be skipped in the last argument of the PostProcess pragma. For example, let’s say that you want to change the variable “foo” into “foobar” anywhere in your project except the methods named FunctionOne, SubTwo, and PropertyThree you can use the following pragma:

         '##  PostProcess "\bfoo\b", "foobar", True, False, 
                 "(Sub|Function|Property)[  \t]+(?!(FunctionOne|SubTwo|PropertyThree)\b).+?
                 (End Sub|End Function|End  Property)"

In the second approach you can mark all the methods that you want to skip with a special comment (for example “SKIP”) and use the following pragma:

         '##  PreProcess "\bfoo\b", "foobar", True, False, 
                "\r\n(?![  \t]*'SKIP)[^\r]*\r\n[ \t]*(Private|Public|Friend)[  \t]*
                (?<kind>Sub|Function|Property)[ \t].+?(End[ \t]+\k<kind>)"


         Private  Sub DoSomething()
             Dim foo As Integer
             foo = 25
         End  Sub

Notice that the latter approach works fine only with the PreProcess pragma; when applied to the PostProcess pragma it works well only if the source file doesn’t contain any Property procedure, because during the migration the position of these procedures (and therefore the remarks associated to them) are moved around in the generated .NET code.

Unfortunately, neither approach works well when converting to C#, because C# methods are closed by a generic curly brace rather than a more descriptive End Sub or End Function keyword.


Previous | Index | Next