本文整理汇总了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"));
}
示例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"));
}
示例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"));
}
示例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"));
}
示例5: GetValueFromParent
public void GetValueFromParent()
{
Context parent = new Context();
Context context = new Context(parent);
parent.SetValue("One", 1);
Assert.AreEqual(1, context.GetValue("One"));
}
示例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"));
}
示例7: SetAndGetValue
public void SetAndGetValue()
{
Context context = new Context();
context.SetValue("a", "One");
Assert.AreEqual("One", context.GetValue("a"));
}
示例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));
}
示例9: DefineVariable
public void DefineVariable()
{
Context context = new Context();
context.DefineVariable("x");
Assert.AreEqual(Undefined.Instance, context.GetValue("x"));
}
示例10: SetAndGetValue
public void SetAndGetValue()
{
Context context = new Context();
context.SetValue("one", 1);
Assert.AreEqual(1, context.GetValue("one"));
}
示例11: MatchAnonymousVariable
public void MatchAnonymousVariable()
{
Context context = new Context();
Assert.IsTrue(MatchUtilities.MatchObjects(new Variable("_"), 1, context));
Assert.IsNull(context.GetValue("_"));
}
示例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"));
}
示例13: SetAndGetValue
public void SetAndGetValue()
{
var ctx = new Context<object>();
ctx.SetValue("foo", 42);
Assert.AreEqual(42, ctx.GetValue("foo"));
}
示例14: MatchVariableInverse
public void MatchVariableInverse()
{
Context context = new Context();
Assert.IsTrue(MatchUtilities.MatchObjects(1, new Variable("X"), context));
Assert.AreEqual(1, context.GetValue("X"));
}
示例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"));
}