Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 3 Current »

One of our default metalang files (vbmethods.xml) has this definition of VB6.Split method:

  <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>

It indicates that the last three args are optional. 

Another default metalang file (VBASIC.XML) has these standard target patterns for Split:

      <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 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:

         <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:

   <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.  

  • No labels