NOTE: starting with build 1.00.05, VB Migration Partner automatically refactors expressions based on the “Is” operator and introduces the “IsNot” operator if possible, therefore the technique described in this article is now obsolete. However, we haven’t withdrawn the article because it illustrates an advanced application of the PostProcess pragma.
VB.NET supports the IsNot operator, which permits to simplify expressions such as
If Not x Is Nothing Then
Do
…
Loop Until Not x Is Nothing
End If
into a more readable:
If x IsNot Nothing Then
Do
…
Loop Until x IsNot Nothing
End If
VB Migration Partner doesn’t automatically refactor expressions to leverage the IsNot operator, but you can easily reach the same effect by means of the following PostProcess pragma:
The above regular expression is a bit aggressive and might have one or more false matches, which in turn would generate statements that are invalid or that don’t behave as expected. If you realize that the pragma replace strings that it shouldn’t replace, you can try with the following, more granular pragmas: