本文整理汇总了C#中ExecutionContext.GetVariable方法的典型用法代码示例。如果您正苦于以下问题:C# ExecutionContext.GetVariable方法的具体用法?C# ExecutionContext.GetVariable怎么用?C# ExecutionContext.GetVariable使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ExecutionContext
的用法示例。
在下文中一共展示了ExecutionContext.GetVariable方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Execute
public override string Execute(ExecutionContext context)
{
string varName = VariableName.ToString();
context.SetLocalVariable(varName, context.IsVariableSet(varName) ? context.GetVariable(varName) : null);
return "";
}
示例2: TestFormat
public void TestFormat()
{
var context = new ExecutionContext();
var formatFunc = (ExecutionContext.OsqFunction)context.GetVariable("format");
var ret = formatFunc(new TokenNode(null, new[] {
new TokenNode(new Token(TokenType.Symbol, ","), new[] {
new TokenNode(new Token(TokenType.String, "this is a {0} {1:D9}")),
new TokenNode(new Token(TokenType.String, "test")),
new TokenNode(new Token(TokenType.Number, 10)),
})
}), context);
Assert.AreEqual("this is a test 000000010", ret);
}
示例3: Evaluate
public object Evaluate(ExecutionContext context)
{
switch(Token.TokenType) {
default:
case TokenType.Number:
case TokenType.String:
return Token.Value;
case TokenType.Identifier:
case TokenType.Symbol:
object item = context.GetVariable(Token.Value.ToString());
var asFunc = item as ExecutionContext.OsqFunction;
return asFunc == null ? item : asFunc.Invoke(this, context);
}
}
示例4: Execute
public override string Execute(ExecutionContext context)
{
var output = new StringBuilder();
double counter = Convert.ToDouble(Start.Evaluate(context), Parser.DefaultCulture);
while(true) {
context.SetVariable(Variable, counter);
output.Append(ExecuteChildren(context));
counter = Convert.ToDouble(context.GetVariable(Variable), Parser.DefaultCulture);
counter += Step == null ? 1.0 : Convert.ToDouble(Step.Evaluate(context), Parser.DefaultCulture);
if(counter >= Convert.ToDouble(End.Evaluate(context), Parser.DefaultCulture)) {
break;
}
}
return output.ToString();
}
示例5: TestMin
public void TestMin()
{
var context = new ExecutionContext();
var formatFunc = (ExecutionContext.OsqFunction)context.GetVariable("min");
var ret = formatFunc(new TokenNode(null, new[] {
new TokenNode(new Token(TokenType.Symbol, ","), new[] {
new TokenNode(new Token(TokenType.Number, 10)),
new TokenNode(new Token(TokenType.Number, 100)),
})
}), context);
Assert.AreEqual(10, ret);
}
示例6: TestInt
public void TestInt()
{
var context = new ExecutionContext();
var formatFunc = (ExecutionContext.OsqFunction)context.GetVariable("int");
var ret = formatFunc(new TokenNode(null, new[] {
new TokenNode(new Token(TokenType.Number, 13.37)),
}), context);
Assert.AreEqual(13, ret);
}