Ejemplo n.º 1
0
        static void Main(string[] args)
        {
            var expression = new CSharpScript("1 + a.a")
            {
                ExecuteInSeparateAppDomain = true
            };

            // This snippet shows how a class on a assembly in the GAC can be used
            using (expression)
            {
                expression.AddObjectInScope("a", new TestClassInGACAssembly());
                Console.WriteLine(expression.Execute());
            }

            // This snippet shows how building a SovosExpando, in an assembly installed in GAC works fine.
            // You can call all methods dynamically from the C# script
            using (expression = new CSharpScript()
            {
                ExecuteInSeparateAppDomain = true
            })
            {
                var expando = SovosExpandoBuilder.Build();
                expression.AddObjectInScope("sovosExpando", expando);
                expression.AddCodeSnippet(
                    @"var v = sovosExpando.Test; // We read here a property that gets created on-the-fly
            sovosExpando.Test = ""Hola Mundo""; // We enter a value here that will be cleared by ResetTest() call
            sovosExpando.ResetTest(); // We invoke a dynamically created method here
            sovosExpando.Test = v + sovosExpando.Test + ""Hello World""; // We use here the property read on-the-fly and stored in v
            return sovosExpando.Test");
                Console.WriteLine(expression.Execute());
            }
        }
 public void CodeSnippet_Success()
 {
     using (var expression = new CSharpScript())
     {
         Assert.AreEqual(0, expression.AddCodeSnippet("var i = 1; return 1 + i"));
         Assert.AreEqual(2, expression.Execute());
     }
 }
 public void ClassSnippet_Success()
 {
     using (var expression = new CSharpScript())
     {
         expression.AddMember(
             @"private class Tester {
     public static int Test() {
       return 10;
     }
   }");
         Assert.AreEqual(0, expression.AddCodeSnippet("var i = 1; return Tester.Test() + i"));
         Assert.AreEqual(11, expression.Execute());
     }
 }
 public void UseCustomExpandoObjectWithProperty_Success()
 {
     using (var expression = new CSharpScript())
     {
         var expando = SovosExpandoBuilder.Build();
         expression.AddObjectInScope("sovosExpando", expando);
         expression.AddCodeSnippet(
             @"var v = sovosExpando.Test; // We read here a property that gets created on-the-fly
     sovosExpando.Test = ""Hola Mundo""; // We enter a value here that will be cleared by ResetTest() call
     sovosExpando.ResetTest(); // We invoke a dynamically created method here
     sovosExpando.Test = v + sovosExpando.Test + ""Hello World""; // We use here the property read on-the-fly and stored in v
     return sovosExpando.Test");
         Assert.AreEqual("Hello World", expression.Execute());
     }
 }