Setting and Returning functions to .net

Apr 5, 2010 at 12:08 PM


Just playing around with Jint and I must say it found it to be very interesting.  In one of my samples, I was populating a .net object. I realised that for all functions the value was null.

Below is the code I used

public TestClass{
   public string name{get;set;}
   public int age{get;set;}
   public Func<string,string> fn {get;set;}

static void Main(string[] args){
  var engine = new JintEngine();
  engine.SetFunction("toSource", new Func<object,string>(ObjToJsonString)); //some function with return JsonConvert.SerializeObject(o)
 engine.Run(@" function fillData(v){ = 'ritNCoder'; v.age = 35; v.fn = function(x){ return toSource(x);}; return function(){ return true; } } " ); var int = new TestClass1(); engine.SetParameter("d",inst); var obj2 = engine.Run("return fillData(d);"); Console.ReadKey();

At the end of the call,

inst.fn is null and obj2 is also null. It appears functions are not returned. I had a conversion exception earlier which appears to be resolved after following the discussions. I've not seen anything about functions yet. Is it already implemented or it is not available. If not, can I be directed on how to do this.