Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- engine.SetGlobalValue("TestViewModel", new ScriptResultConstructor(engine));
- engine.ExecuteFile(@"c:testtest.js");
- Console.WriteLine(engine.CallGlobalFunction("testViewModel"))
- public class ScriptResultConstructor : ClrFunction
- {
- public ScriptResultConstructor(ScriptEngine engine)
- : base(engine.Function.InstancePrototype, "TestViewModel",
- new ScriptResultInstance(engine.Object.InstancePrototype))
- {
- }
- [JSConstructorFunction]
- public ScriptResultInstance Construct()
- {
- return new ScriptResultInstance(InstancePrototype);
- }
- }
- public class ScriptResultInstance : ObjectInstance
- {
- public bool Result { get; set; }
- public string Message { get; set; }
- public ScriptResultInstance(ObjectInstance prototype)
- : base(prototype)
- {
- PopulateFunctions();
- }
- public ScriptResultInstance(ObjectInstance prototype, bool result, string message)
- : base(prototype)
- {
- Result = result;
- Message = message;
- }
- [JSFunction(Name = "TestScriptResult")]
- public ScriptResultInstance TestScriptResult()
- {
- var model = new ScriptResultInstance(Engine.Object.InstancePrototype, true, "ok");
- return model;
- }
- }
- function testViewModel() {
- var str = new TestViewModel();
- return str.TestScriptResult().Message;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement