[Mono-devel-list] VB.NET runtime

Dave Mertens dmertens at zyprexia.com
Wed Jul 21 07:18:48 EDT 2004

>  On Tue, 2004-07-20 at 04:48, A Rafael D Teixeira wrote:
>  > That is true, but what is missing is how to create the 
>  defaultvalue 
>  > metadata. That feature is not available as an attribute. There are 
>  > attributes to govern how non-simple values (DateTimes and 
>  Decimals, 
>  > for
>  > example) are stored as default values, but not to say the default 
>  > value itself.
>  Sure, it's not, but is there any reason why it *can't* be 
>  available as an attribute?

There is actually an attribute for setting the defaultvalue. It's simply
called DefaultValueAttribute	and can be found in the
System.ComponentModel namespace.

A call with an optional argument with a default value would be like this:
Public static function abc(def as string, <Optional><DefaultValue("xyz")>klm
as string) as string
End function

Another way of 'simulating' optional parameters with a default value is
creating an overloaded function with the specifec argument missing which
calls on his turn the 'original' with the specific argument hardcoded in the
Whenever a value is given for the optional value, the CLR will use directly
the original method.

An example:
Public static function abc(def as string) as string
	return abc(def, "xyz")	'xyz is here the default value
End function
Public static function abc(def as string, klm as string) as string
End function

Both OptionalAttribute and DefaultValueAttribute classes are CLS compliant.
But the use of them is discouraged because method overloading is a far
better way for implementing default values. Still using the optional keyword
in VB.Net is just bad programming..

>  A few random ideas:
>  * A utility that takes an assembly using the attribute, 
>  removes the attribute and adds the relevant IL.
>  * This is the class libraries, so presumably they only need 
>  to run on the mono runtime. I believe you could make the 
>  runtime recognize the attribute.
It's not only the Mono runtime. If an feature called 'optional values' will
be introduced to mono runtime.  But I guess for then only programming for
Mono and not cross-platform. I want to use the binairies on BOTH windows and
linux and don't want the install mono under windows, because I already have
the MS runtimme..

Aside from that, it should be the VB.NET compiler which needs to make the
changes. This would also mean that the binary is cross-platform. But all of
that is unnessacery because .NET already have those features.

Dave Mertens

More information about the Mono-devel-list mailing list