Using C# classes

Dec 5, 2009 at 12:37 PM

I have various classes written in C# that I want to use from javascript, I can create them in my script like so:

 

var c = new UI.ImageBox(RootControl, t);

 

However, these are of no use, I cannot use any of the methods of my class, for example

 

c.SetSize(100, 100);

 

Will fail, throwing a MethodNotFound exception, with message "Method not found with specified arguments: SetSize", Such a method does exist (taking 2 integers). With a little investigation I found that I can change this by adding a method to ImageBox which takes 2 objects and casts them to integers, however now I get a cast invalid exception.

 

Is there a way to use library classes besides .net ones? I cannot modify all my libraries to accept objects and cast parameters!

Coordinator
Dec 5, 2009 at 12:46 PM

Could you try forcing the type like this:

c.SetSize(ToInt32(100), ToInt32(100));

Internalyy I'm looking for a method with the parameter types corresponding to the ones passed as parameter. Though they are handled as double internally, and your method is not found. In the next release, you'll see it's automatically handled. So for the moment you have to cast the parameters.

Cheers,
Sébastien

Dec 5, 2009 at 2:54 PM

That almost works, but I have something rather odd. This code works:

 

var x = ToInt32(100);
var y = ToInt32(100);
c.SetSize(x, y);

 

But this code throws a NullReferenceException

 

c.SetSize(ToInt32(100), ToInt32(100));

 

I've encountered this before, trying to inline method calls always throws that kind of exception.

Coordinator
Dec 5, 2009 at 3:07 PM

I have just added a unit test for this and it works from my code base. You need to wait the next release, or I can send one directly if you ask for it.

Sébastien

Dec 5, 2009 at 3:21 PM

May I have a copy of the next version then please? Do you want to email it to me?

 

How come you don't use the svn, out of interest?

Coordinator
Dec 5, 2009 at 3:24 PM

We do use SVN, our own actually. You can access it here: https://svn.evaluant.com:8443/svn/jint. User and password are svnuser.

Enjoy. Or contact me via the contact form to get a direct email conversation and I'll send you a specific release.

Dec 5, 2009 at 3:26 PM

Aha excellent, thankyou very much. I'll get the latest SVN release :)

Dec 5, 2009 at 3:50 PM

It works now, thanks for the help

Dec 5, 2009 at 5:16 PM

I have a similar problem now. I have a method which accepts an instance of one of my own classes. Of course the interpreter looks for a method accepting an object. Is there a method forcing it to cast objects into certain types?

Coordinator
Dec 5, 2009 at 5:19 PM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.