コード例 #1
0
 public void InvokeMethodTwice_Success()
 {
     using (var expression = new CSharpScript())
     {
         expression.AddMember(
             @"public int Test() {
       return 10;            
     }");
         Assert.AreEqual(10, expression.Invoke("Test", null));
         Assert.AreEqual(10, expression.Invoke("Test", null));
     }
 }
コード例 #2
0
 public void CreateTwoObjectsMaintainingDifferentState_Success()
 {
     using (var script = new CSharpScript())
     {
         script.AddMember(
             @"public void Test(int a) {  
       global.a = a;                            
     }");
         script.AddExpression("global.a");
         var obj_a = script.CreateScriptObject();
         var obj_b = script.CreateScriptObject();
         Assert.AreEqual(null, script.Invoke(obj_a, "Test", new object[] { 5 }));
         Assert.AreEqual(null, script.Invoke(obj_b, "Test", new object[] { 10 }));
         Assert.AreEqual(5, script.Execute(obj_a));
         Assert.AreEqual(10, script.Execute(obj_b));
     }
 }
コード例 #3
0
 public void InvokeMethodWithParams_Success()
 {
     using (var expression = new CSharpScript())
     {
         expression.AddMember(
             @"public int Test(int a) {       
       return a;            
     }");
         Assert.AreEqual(5, expression.Invoke("Test", new object[] { 5 }));
     }
 }
コード例 #4
0
 public void CreateTwoObjectsWithObjectInScopeResettingIt_Success()
 {
     using (var script = new CSharpScript())
     {
         script.AddMember(
             @"public void Test(int a) {  
       global.a = a;                            
     }");
         script.AddExpression("global.a + i");
         script.AddObjectInScope("i", 1);
         var obj_a = script.CreateScriptObject();
         var obj_b = script.CreateScriptObject();
         Assert.AreEqual(null, script.Invoke(obj_a, "Test", new object[] { 5 }));
         Assert.AreEqual(null, script.Invoke(obj_b, "Test", new object[] { 10 }));
         Assert.AreEqual(6, script.Execute(obj_a));
         Assert.AreEqual(11, script.Execute(obj_b));
         script.ReplaceObjectInScope(obj_a, "i", 2);
         Assert.AreEqual(7, script.Execute(obj_a));
         Assert.AreEqual(11, script.Execute(obj_b));
     }
 }
コード例 #5
0
 public void InvokeVoidMethodWithParamsModifyGlobals_Success()
 {
     using (var expression = new CSharpScript())
     {
         expression.AddMember(
             @"public void Test(int a) {  
       global.a = a;                            
     }");
         expression.AddExpression("global.a");
         Assert.AreEqual(null, expression.Invoke("Test", new object[] { 5 }));
         Assert.AreEqual(5, expression.Execute());
     }
 }
コード例 #6
0
 public void InvokeMethodWithParamsModifyGlobalsMultiAppDomain_Success()
 {
     using (var expression = new CSharpScript())
     {
         expression.ExecuteInSeparateAppDomain = true;
         expression.AddMember(
             @"public int Test(int a) {  
       global.a = 20;     
       return a;            
     }");
         expression.AddExpression("global.a");
         Assert.AreEqual(5, expression.Invoke("Test", new object[] { 5 }));
         Assert.AreEqual(20, expression.Execute());
     }
 }