[Mono-devel-list] VB.NET runtime

Rob.Tillie at Student.tUL.EDU Rob.Tillie at Student.tUL.EDU
Fri Jul 23 15:24:00 EDT 2004


Hey Dave,

Everything now has a DefaultValueAttribute in the MS.VB namespace, but this
is the wrong one, that's why it is in System.ComponentModel. It is primarily
used for IDEs. In short, the thing doesn't emit the IL code for an optional
parameter, and shouldn't do this either.
Please look in the archives of the list, this already has been discussed.

(PS: I know it is bad programming, but since we want to be API compatible we
need the correct signature, we can't accomplish this by using overloads...)

Thanks for the input!

Greetz,
-- Rob.

> -----Original Message-----
> From: Dave Mertens [mailto:dmertens at zyprexia.com]
> Sent: Wednesday, July 21, 2004 1:19 PM
> To: 'Iain McCoy'; 'A Rafael D Teixeira'
> Cc: mono-devel-list at lists.ximian.com; mono-vb-list at lists.ximian.com
> Subject: RE: [Mono-devel-list] VB.NET runtime
> 
> >
> >  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
> call.
> 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.
> 
> 
> Regards,
> Dave Mertens
> 
> _______________________________________________
> Mono-devel-list mailing list
> Mono-devel-list at lists.ximian.com
> http://lists.ximian.com/mailman/listinfo/mono-devel-list



More information about the Mono-devel-list mailing list