当前位置: 首页>>代码示例>>C#>>正文


C# Interpreter.SetVariable方法代码示例

本文整理汇总了C#中Interpreter.SetVariable方法的典型用法代码示例。如果您正苦于以下问题:C# Interpreter.SetVariable方法的具体用法?C# Interpreter.SetVariable怎么用?C# Interpreter.SetVariable使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Interpreter的用法示例。


在下文中一共展示了Interpreter.SetVariable方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: SystemExceptions_are_preserved_using_method_invocation

        public void SystemExceptions_are_preserved_using_method_invocation()
        {
            var target = new Interpreter();
            target.SetVariable("a", new MyTestService());

            target.Eval("a.ThrowException()");
        }
开发者ID:jony1982,项目名称:DynamicExpresso,代码行数:7,代码来源:ExceptionTest.cs

示例2: Can_use_overloaded_operators_on_class

        public void Can_use_overloaded_operators_on_class()
        {
            var target = new Interpreter();

            var x = new ClassWithOverloadedBinaryOperators(3);
            target.SetVariable("x", x);

            string y = "5";
            Assert.IsFalse(x == y);
            Assert.IsFalse(target.Eval<bool>("x == y", new Parameter("y", y)));

            y = "3";
            Assert.IsTrue(x == y);
            Assert.IsTrue(target.Eval<bool>("x == y", new Parameter("y", y)));

            Assert.IsFalse(target.Eval<bool>("x == \"4\""));
            Assert.IsTrue(target.Eval<bool>("x == \"3\""));

            Assert.IsTrue(!x == "-3");
            Assert.IsTrue(target.Eval<bool>("!x == \"-3\""));

            var z = new ClassWithOverloadedBinaryOperators(10);
            Assert.IsTrue((x + z) == "13");
            Assert.IsTrue(target.Eval<bool>("(x + z) == \"13\"", new Parameter("z", z)));
        }
开发者ID:jony1982,项目名称:DynamicExpresso,代码行数:25,代码来源:OperatorsTest.cs

示例3: Registered_custom_identifiers_are_saved_inside_the_interpreter

		public void Registered_custom_identifiers_are_saved_inside_the_interpreter()
		{
			var target = new Interpreter();

			target.SetVariable("x", null);

			Assert.IsTrue(target.Identifiers.Any(p => p.Name == "x"));
		}
开发者ID:CooperLiu,项目名称:DynamicExpresso,代码行数:8,代码来源:IdentifiersTest.cs

示例4: Simulate_a_working_context_using_this_keyword

        public void Simulate_a_working_context_using_this_keyword()
        {
            var workingContext = new { FirstName = "homer" };

            var interpreter = new Interpreter();
            interpreter.SetVariable("this", workingContext);

            Assert.AreEqual(workingContext.FirstName, interpreter.Eval("this.FirstName"));
        }
开发者ID:nishannnb,项目名称:DynamicExpresso,代码行数:9,代码来源:WorkingContextTest.cs

示例5: Injection_a_property_expresion_to_simulate_a_working_context_parsing_another_property

        public void Injection_a_property_expresion_to_simulate_a_working_context_parsing_another_property()
        {
            var workingContext = new { FirstName = "homer" };

            var interpreter = new Interpreter();
            interpreter.SetVariable("this", workingContext);
            var firstNameExpression = interpreter.Parse("this.FirstName").LambdaExpression.Body;
            interpreter.SetExpression("FirstName", firstNameExpression);

            Assert.AreEqual(workingContext.FirstName, interpreter.Eval("FirstName"));
        }
开发者ID:nishannnb,项目名称:DynamicExpresso,代码行数:11,代码来源:WorkingContextTest.cs

示例6: Unary_Cast_Operator

		public void Unary_Cast_Operator()
		{
			var target = new Interpreter();

			var x = 51.5;
			target.SetVariable("x", x);

			Assert.AreEqual((int)x, target.Eval("(int)x"));
			Assert.AreEqual(typeof(int), target.Parse("(int)x").ReturnType);
			Assert.AreEqual(typeof(object), target.Parse("(object)x").ReturnType);
			Assert.AreEqual((double)84 + 9 * 8, target.Eval("(double)84 + 9 *8"));
		}
开发者ID:CooperLiu,项目名称:DynamicExpresso,代码行数:12,代码来源:OperatorsTest.cs

示例7: CustomExceptions_WithoutSerializationConstructor_are_preserved

        public void CustomExceptions_WithoutSerializationConstructor_are_preserved()
        {
            var target = new Interpreter();

            Func<string> testException = new Func<string>(() =>
            {
                throw new MyException("Test");
            });

            target.SetVariable("testException", testException);

            target.Eval("testException()");
        }
开发者ID:johniak,项目名称:DynamicExpresso,代码行数:13,代码来源:OtherTests.cs

示例8: Variables_can_be_overwritten_in_a_case_insensitive_setting

		public void Variables_can_be_overwritten_in_a_case_insensitive_setting()
		{
			var target = new Interpreter(InterpreterOptions.DefaultCaseInsensitive)
											.SetVariable("myk", 23);

			Assert.AreEqual(23, target.Eval("myk"));

			target.SetVariable("MYK", 3489);

			Assert.AreEqual(3489, target.Eval("myk"));

			Assert.AreEqual(typeof(int), target.Parse("myk").ReturnType);
		}
开发者ID:CooperLiu,项目名称:DynamicExpresso,代码行数:13,代码来源:VariablesTest.cs

示例9: Variables_can_be_overwritten

		public void Variables_can_be_overwritten()
		{
			var target = new Interpreter()
											.SetVariable("myk", 23);

			Assert.AreEqual(23, target.Eval("myk"));

			target.SetVariable("myk", 3489);

			Assert.AreEqual(3489, target.Eval("myk"));

			Assert.AreEqual(typeof(int), target.Parse("myk").ReturnType);
		}
开发者ID:CooperLiu,项目名称:DynamicExpresso,代码行数:13,代码来源:VariablesTest.cs

示例10: SystemExceptions_are_preserved_using_delegate_variable

        public void SystemExceptions_are_preserved_using_delegate_variable()
        {
            var target = new Interpreter();

            Func<string> testException = new Func<string>(() =>
            {
                throw new InvalidOperationException("Test");
            });

            target.SetVariable("testException", testException);

            target.Eval("testException()");
        }
开发者ID:jony1982,项目名称:DynamicExpresso,代码行数:13,代码来源:ExceptionTest.cs

示例11: RuleBuilder

 public RuleBuilder(IpTablesSystem system, String nfbpf, Dictionary<int, IpTablesRuleSet> ruleSets, FunctionRegistry functions = null)
 {
     if (functions == null)
     {
         functions = new FunctionRegistry();
     }
     _system = system.System;
     _nfbpf = nfbpf;
     var chainsDict =
         ruleSets.Select((a) => new KeyValuePair<int, IpTablesChainSet>(a.Key, a.Value.Chains))
             .ToDictionary((a) => a.Key, (a) => a.Value);
     _dcr = new DynamicChainRegister(system, chainsDict);
     _formatDb = new DynamicDictionary<object>(_mappings);
     _ruleSets = ruleSets;
     _interpreter = new Interpreter();
     _interpreter.SetVariable("var", _mappings);
     functions.LoadFunctions(_interpreter);
 }
开发者ID:splitice,项目名称:YFW.Net,代码行数:18,代码来源:RuleBuilder.cs

示例12: Throw_an_exception_if_a_custom_type_doesnt_define_plus_operator

        public void Throw_an_exception_if_a_custom_type_doesnt_define_plus_operator()
        {
            var target = new Interpreter();

            var x = new TypeWithoutOverloadedBinaryOperators(3);
            target.SetVariable("x", x);

            int y = 5;
            target.Parse("x + y", new Parameter("y", y));
        }
开发者ID:jony1982,项目名称:DynamicExpresso,代码行数:10,代码来源:OperatorsTest.cs

示例13: Throw_an_exception_if_a_custom_type_doesnt_define_not_operator

        public void Throw_an_exception_if_a_custom_type_doesnt_define_not_operator()
        {
            var target = new Interpreter();

            var x = new TypeWithoutOverloadedBinaryOperators(3);
            target.SetVariable("x", x);

            target.Parse("!x");
        }
开发者ID:jony1982,项目名称:DynamicExpresso,代码行数:9,代码来源:OperatorsTest.cs


注:本文中的Interpreter.SetVariable方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。