One of our default metalang files (vbmethods.xml
) has this definition of VB6.the VB6 Split method:
Code Block |
---|
<method id="Split" type="String[]" opcode="VBF.112"> <argument id="Expression" type="String" status="ByVal"/> <argument id="Delimiter" type="String" status="ByVal" optional=" "/> <argument id="Limit" type="Integer" status="ByVal" optional="-1"/> <argument id="Compare" type="VbCompareMethod" status="ByVal" optional="1"/> </method> |
...
Another default metalang file (VBASIC.XML
) has these standard target patterns for Split:
Code Block |
---|
<subcode id="Split"> <loc status="extension" role="function" narg="4" code="%1d.Split(%2d)"/> <vbn role="function" narg="4" code="Strings.Split(%1d,%2d,%3d,%4d)"/> <jvs role="function" narg="4" code="Split(%1d,%2d)"/> <csh role="function" narg="4" code="VBNET.Strings.Split(%1d,%2d,%3d,%4d)"/> </subcode> |
Notice that the loc
form explicitly omits all arguments but the second one. This is to fit within the limits of the BCL String.Split.
Our MigrationSupport.dll has overloaded extension methods that support different number of arguments and they are available to your code.
To take advantage of these overloaded extension methods you need to use a custom metalang configuration. You can activate a custom metalang file from the settings Settings form. Find vbasic.xml
in the Metalang files list, then right click and select Activate
. This will copy the default file to your user folder and modify the metalang script to reference that copy. Repeat the process for vbmethods.xml
.
Next, open the usr
\/VBASIC.XML
file and change the loc
target pattern for Split
. Use %o
notation in a target pattern to tell the tool to only emit an actual argument if one was specified in the source. For example:
Code Block |
---|
<loc status="extension" role="function" narg="4" code="%1d.Split(%2d,%3o,%4o)"/> |
Note the above changes will author a ",," malformation if actual arg 4 is given and arg 3 is omitted in a call. Normally, this is not a big issue, ; however if it is, custom handling of the Split
operation will be needed to select different patterns.
Then in usr
\/vbmethods.xml
mark the last two arguments as overloaded:
Code Block |
---|
<method id="Split" type="String[]" opcode="VBF.112"> <argument id="Expression" type="String" status="ByVal"/> <argument id="Delimiter" type="String" status="ByVal" optional=" "/> <argument id="Limit" type="Integer" status="ByVal" optional="DEF.Overload"/> changed <argument id="Compare" type="VbCompareMethod" status="ByVal" optional="DEF.Overload"/> changed </method> |
Use snapshot, translate, compare to check the result.