How to pas a class to Jint?

Mar 13, 2010 at 3:58 PM

I am new to jint. I have created a class in C# that I want the users to be able to initialize it in javascript. Example.

Here is a sample class

 

public class A
{
    public int B;
    public bool C;

    public A()
    {
        B = 3;
        C = true;
    }
}

Here is a sample javascript code.

var a = new A();
a.B = 5;
a.C = false;

return a;

 

I don't want to enable CLR. The source of the javascript code is not trusted.

How can I do this?

Mar 15, 2010 at 9:41 AM

There is a specific section for it in the Documentation tab: http://jint.codeplex.com/wikipage?title=Using%20.NET%20classes%20from%20scripts&referringTitle=Documentation
You just have to fully qualify your class, like "new NamespaceX.NamespaceY.YouClass()"

Also, you should trust Jint's security mecanism. This is explained in the same page of the documentation.

May 2, 2010 at 7:17 AM
Edited May 2, 2010 at 7:27 AM

I have the same problem and the solution with the namespaces won't work for me, because the Scripts are third party. 

How can i map some .NET class so that this works and redirects to some CLR class like MyNamespace.MyClassA,
In fact i want to get something like a build in type A that is implemented as some sort of CLR type.

var a = new A();