Advertisement
Guest User

Untitled

a guest
Apr 17th, 2014
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.33 KB | None | 0 0
  1. engine.SetGlobalValue("TestViewModel", new ScriptResultConstructor(engine));
  2. engine.ExecuteFile(@"c:testtest.js");
  3. Console.WriteLine(engine.CallGlobalFunction("testViewModel"))
  4.  
  5. public class ScriptResultConstructor : ClrFunction
  6. {
  7. public ScriptResultConstructor(ScriptEngine engine)
  8. : base(engine.Function.InstancePrototype, "TestViewModel",
  9. new ScriptResultInstance(engine.Object.InstancePrototype))
  10. {
  11.  
  12. }
  13. [JSConstructorFunction]
  14. public ScriptResultInstance Construct()
  15. {
  16. return new ScriptResultInstance(InstancePrototype);
  17. }
  18. }
  19. public class ScriptResultInstance : ObjectInstance
  20. {
  21. public bool Result { get; set; }
  22. public string Message { get; set; }
  23.  
  24. public ScriptResultInstance(ObjectInstance prototype)
  25. : base(prototype)
  26. {
  27. PopulateFunctions();
  28. }
  29.  
  30. public ScriptResultInstance(ObjectInstance prototype, bool result, string message)
  31. : base(prototype)
  32. {
  33. Result = result;
  34. Message = message;
  35.  
  36. }
  37. [JSFunction(Name = "TestScriptResult")]
  38. public ScriptResultInstance TestScriptResult()
  39. {
  40.  
  41. var model = new ScriptResultInstance(Engine.Object.InstancePrototype, true, "ok");
  42. return model;
  43. }
  44.  
  45.  
  46.  
  47. }
  48.  
  49. function testViewModel() {
  50. var str = new TestViewModel();
  51. return str.TestScriptResult().Message;
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement