How can i override operator with Jint

Oct 27, 2010 at 8:01 PM
Edited Oct 27, 2010 at 8:01 PM

I have C# class with overrided operators. How can i make those overrided operators available in script run by JintEngine. Can SetFunction be helpfull ?

Sample:

public class Book {

....

  public static Book operator + (Book b1, Book b2) {  ...  }

  public static Book CreateBook() { ... }

....

}

In the main program I have :

JintEngine engin = new JintEngine();

engin.SetFunction("CreateBook", new Func<Book>(a => { return Book.CreateBook();}));

string script = " var b1 = CreateBook(); var b2 = CreateBook(); var b = b1+b2;"

engine.Run(script); 

The line engine.Run(script) do not run correctly because of operation b1+b2. How can i make this work correctly ?