Specifying overloaded Constructors

Apr 26, 2010 at 3:52 PM

From the Console:

(clr-new Bitmap 10 10)

#(clr-type System.Drawing.Bitmap)

(define h 10)

(clr-new Bitmap h h)

Unhandled CLR exception during evaluation:

CLR Exception: System.InvalidCastException

System.InvalidCastException: Unable to cast object of type 'System.Int32' to type 'System.String'


As far as I can tell, when you give it the value wrapped in a variable, it's choosing the wrong constructor, defaulting to the String version.  Any help?

Coordinator
Apr 26, 2010 at 4:05 PM

Hi

While constructors are not handled as nicely as methods, it can still be done. Here is an example:

> (clr-reference System.Drawing)
> (clr-using System.Drawing)
> (define h 10)
> (define bm (clr-new Bitmap (clr-cast Int32 h) (clr-cast Int32 h)))
> bm
#<clr-type System.Drawing.Bitmap>

Hope this helps :)