[mono-vb] Microsoft.VisualBasic.dll gets support for default values for optional parameters

Ankit Jain Ankit Jain <radical@gmail.com>
Thu, 21 Apr 2005 18:23:20 +0530


A long known problem with mono for VB.Net developers was that
Microsft.VisualBasic.* didn't support default values for optional
parameters. The problem has been nicely explained by Jambu at
http://www.gnomebangalore.org/?q=3Dnode/view/498. I had written about it
in my blog about a month back.

In short, the problem is that Microsoft.VisualBasic.* has been written
in C#, and since C# doesn't have a concept of default values or
optional parameters.. these cant be represented in a straight-forward
manner. So, Jambu created a DefaultArgumentValueAttribute which could
be used for a method parameter to specify its default value. But this
has to be converted from being a custom attribute to actual metadata
in dll as the default value.

So, the idea is -> dissassemble Microsoft.VisualBasic.dll -->
fixup_with_script --> assemble back.
Writing the script wasnt much of a problem, but it turned out that
monodis and ilasm had *some* bugs cos of which the "roundtrip" wouldnt
work (http://mono-nosip.blogspot.com/). So, after a long series of bug
fixes to ilasm/monodis/runtime(small fixes) .. the roundtripping is
working now.

Hari has integerated the script with the build system. So, nothing
extra needs to be done to take advantage of this now. You can use
methods in Microsoft.VisualBasic.dll which have optional parameters
now. Eg.

Imports System
Imports Microsoft.VisualBasic
module Test1
        sub Main ()
                Console.WriteLine (Strings.Format (5459.4))
        End Sub
end module

Strings.Format takes two parameters, the 2nd one being optional !

Though, i've tried to test the *fixedup_dll*, there will probably be
things that i havent encountered, so would be eagerly waiting for

Special thanks to Hari for this entire work.
Blog :
Mono hacking : http://mono-nosip.blogspot.com
Personal : http://www.corewars.org/radical

Blog :
Mono hacking : http://mono-nosip.blogspot.com
Personal : http://www.corewars.org/radical