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


C# Context.GetValue方法代码示例

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


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

示例1: GetValueUsingParent

        public void GetValueUsingParent()
        {
            Context parent = new Context();
            Context context = new Context(parent);

            parent.SetValue("one", 1);
            Assert.IsTrue(context.HasValue("one"));
            Assert.IsFalse(context.HasValue("two"));
            Assert.AreEqual(1, context.GetValue("one"));
            Assert.IsNull(context.GetValue("two"));
        }
开发者ID:ajlopez,项目名称:AjErl,代码行数:11,代码来源:ContextTests.cs

示例2: DefineSetAndGetAndRemoveVariable

        public void DefineSetAndGetAndRemoveVariable()
        {
            Context context = new Context();

            context.DefineVariable("x");

            context.SetValue("x", 123);
            Assert.AreEqual(123, context.GetValue("x"));

            context.RemoveValue("x");
            Assert.AreSame(Undefined.Instance, context.GetValue("x"));
        }
开发者ID:ajlopez,项目名称:AjScript,代码行数:12,代码来源:ContextTests.cs

示例3: MatchTuplesWithAVariable

        public void MatchTuplesWithAVariable()
        {
            Tuple tuple = new Tuple(new object[] { 1, new Variable("X"), 3 });
            Tuple tuple2 = new Tuple(new object[] { 1, 2, 3 });
            Context context = new Context();
            Assert.IsTrue(tuple.Match(tuple2, context));
            Assert.AreEqual(2, context.GetValue("X"));

            Assert.IsTrue(tuple2.Match(tuple, context));

            Assert.AreEqual(2, context.GetValue("X"));
        }
开发者ID:ajlopez,项目名称:AjErl,代码行数:12,代码来源:TupleTests.cs

示例4: MatchVariableInFunctionalExpression

        public void MatchVariableInFunctionalExpression()
        {
            var one = new IntegerExpression(1);
            var two = new IntegerExpression(2);
            var expr = new FunctionalExpression(new AddIntegersFunction(), new IExpression[] { new NameExpression("a"), new NameExpression("b") });
            var expr1 = new FunctionalExpression(new AddIntegersFunction(), new IExpression[] { one, two });

            Context<IExpression> ctx = new Context<IExpression>();

            Assert.IsTrue(expr.Match(expr1, ctx));

            Assert.AreSame(one, ctx.GetValue("a"));
            Assert.AreSame(two, ctx.GetValue("b"));
        }
开发者ID:ajlopez,项目名称:Husky,代码行数:14,代码来源:FunctionalExpressionTests.cs

示例5: GetValueFromParent

 public void GetValueFromParent()
 {
     Context parent = new Context();
     Context context = new Context(parent);
     parent.SetValue("One", 1);
     Assert.AreEqual(1, context.GetValue("One"));
 }
开发者ID:ajlopez,项目名称:DartSharp,代码行数:7,代码来源:ContextTests.cs

示例6: ForWithAddExpression

        public void ForWithAddExpression()
        {
            var command = new SetVariableCommand("a", new ArithmeticBinaryExpression(ArithmeticOperator.Add, new VariableExpression("k"), new VariableExpression("a")));
            var forcommand = new ForCommand("k", new ConstantExpression(new int[] { 1, 2, 3, 4 }), command);

            Context context = new Context();

            var result = forcommand.Execute(context);

            Assert.IsNull(result);
            Assert.AreEqual("k", forcommand.VariableName);
            Assert.IsNotNull(forcommand.Expression);
            Assert.IsNotNull(forcommand.Command);
            Assert.AreEqual(4, context.GetValue("k"));
            Assert.AreEqual(10, context.GetValue("a"));
        }
开发者ID:ajlopez,项目名称:AjLang,代码行数:16,代码来源:ForCommandTests.cs

示例7: SetAndGetValue

        public void SetAndGetValue()
        {
            Context context = new Context();
            context.SetValue("a", "One");

            Assert.AreEqual("One", context.GetValue("a"));
        }
开发者ID:tario,项目名称:AjScript-migrated,代码行数:7,代码来源:ContextTests.cs

示例8: CreateAndExecuteDefineFunctionCommand

        public void CreateAndExecuteDefineFunctionCommand()
        {
            IEnumerable<ICommand> commands = new ICommand[] {
                new SetVariableCommand("a", new ConstantExpression(1)),
                new SetVariableCommand("b", new ConstantExpression(2))
            };

            CompositeCommand body = new CompositeCommand(commands);
            DefineFunctionCommand command = new DefineFunctionCommand("foo", null, body);

            Context context = new Context();
            Assert.IsNull(command.Execute(context));
            Assert.AreEqual("foo", command.Name);
            Assert.IsNull(command.ArgumentNames);
            Assert.AreEqual(body, command.Command);

            var result = context.GetValue("foo");

            Assert.IsNotNull(result);
            Assert.IsInstanceOfType(result, typeof(DefinedFunction));

            DefinedFunction dfunc = (DefinedFunction)result;

            Assert.AreEqual(2, dfunc.Call(context, null));
        }
开发者ID:ajlopez,项目名称:DartSharp,代码行数:25,代码来源:DefineFunctionCommandTests.cs

示例9: DefineVariable

        public void DefineVariable()
        {
            Context context = new Context();

            context.DefineVariable("x");

            Assert.AreEqual(Undefined.Instance, context.GetValue("x"));
        }
开发者ID:tario,项目名称:AjScript-migrated,代码行数:8,代码来源:ContextTests.cs

示例10: SetAndGetValue

        public void SetAndGetValue()
        {
            Context context = new Context();

            context.SetValue("one", 1);

            Assert.AreEqual(1, context.GetValue("one"));
        }
开发者ID:ajlopez,项目名称:AjErl,代码行数:8,代码来源:ContextTests.cs

示例11: MatchAnonymousVariable

        public void MatchAnonymousVariable()
        {
            Context context = new Context();

            Assert.IsTrue(MatchUtilities.MatchObjects(new Variable("_"), 1, context));

            Assert.IsNull(context.GetValue("_"));
        }
开发者ID:ajlopez,项目名称:AjErl,代码行数:8,代码来源:MatchUtilitiesTests.cs

示例12: DefineAndHasVariable

 public void DefineAndHasVariable()
 {
     Context context = new Context();
     Assert.IsFalse(context.HasVariable("a"));
     context.DefineVariable("a");
     Assert.IsTrue(context.HasVariable("a"));
     Assert.IsNull(context.GetValue("a"));
 }
开发者ID:ajlopez,项目名称:DartSharp,代码行数:8,代码来源:ContextTests.cs

示例13: SetAndGetValue

        public void SetAndGetValue()
        {
            var ctx = new Context<object>();

            ctx.SetValue("foo", 42);

            Assert.AreEqual(42, ctx.GetValue("foo"));
        }
开发者ID:ajlopez,项目名称:Husky,代码行数:8,代码来源:ContextTests.cs

示例14: MatchVariableInverse

        public void MatchVariableInverse()
        {
            Context context = new Context();

            Assert.IsTrue(MatchUtilities.MatchObjects(1, new Variable("X"), context));

            Assert.AreEqual(1, context.GetValue("X"));
        }
开发者ID:ajlopez,项目名称:AjErl,代码行数:8,代码来源:MatchUtilitiesTests.cs

示例15: SetAndGetValueWithParent

 public void SetAndGetValueWithParent()
 {
     Context parent = new Context();
     Context context = new Context(parent);
     context.SetValue("One", 1);
     Assert.AreEqual(1, context.GetValue("One"));
     Assert.IsNull(parent.GetValue("One"));
 }
开发者ID:ajlopez,项目名称:DartSharp,代码行数:8,代码来源:ContextTests.cs


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