本文整理汇总了C#中IToken.Evaluate方法的典型用法代码示例。如果您正苦于以下问题:C# IToken.Evaluate方法的具体用法?C# IToken.Evaluate怎么用?C# IToken.Evaluate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IToken
的用法示例。
在下文中一共展示了IToken.Evaluate方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Evaluate
public override IToken Evaluate(IToken first, IToken last, TokenTreeList parameters, bool isFinal)
{
if (first == null)
throw new Exception($"Operation {Text} can not be unary.");
IToken evaluated = last.Evaluate(parameters, isFinal);
if (evaluated == null)
throw new Exception($"Second element of Operation {Text} is not unique.");
ListToken evaluatedList = evaluated as ListToken;
if (evaluatedList != null)
{
ListToken list = new ListToken();
foreach (IToken item in evaluatedList.Tokens)
list.Tokens.Add(Evaluate(first, item, parameters, isFinal));
return list;
}
IntToken intToken = evaluated as IntToken;
if (intToken == null)
{
if (isFinal)
throw new Exception($"Operation {Text} must have integer second element.");
return new ExpressionToken(first, new IndexOperator(), last);
}
IToken tokenList = first.Evaluate(parameters, isFinal);
ListToken listToken = tokenList as ListToken;
int index = intToken.Value;
return listToken == null
? (index == 0 && tokenList is ITypeToken ? tokenList : new ExpressionToken(first, new IndexOperator(), intToken))
: (listToken.Tokens.Count > index ? listToken.Tokens[index] : new NullToken());
}
示例2: Evaluate
public override IToken Evaluate(IToken first, IToken last, TokenTreeList parameters, bool isFinal)
{
IToken firstList = first.Evaluate(parameters, isFinal);
IToken lastList = last.Evaluate(parameters, isFinal);
if (firstList == null || lastList == null)
throw new Exception($"Operation {Text} is a binary operation.");
return AddToList(firstList, lastList);
}
示例3: Evaluate
public override TokenList Evaluate(IToken first, IToken last, TokenTreeList parameters)
{
if (first == null)
throw new Exception($"Operation {Text} can not be unary.");
TokenList lastList = last.Evaluate(parameters);
if (lastList == null || lastList.Count != 1)
throw new Exception($"Second element of Operation {Text} is not unique.");
IntToken intToken = lastList[0] as IntToken;
if (intToken == null)
throw new Exception($"Operation {Text} must have integer second element.");
return new TokenList(first.Evaluate(parameters)[intToken.Value]);
}
示例4: Evaluate
public override IToken Evaluate(IToken first, IToken last, TokenTreeList parameters, bool isFinal)
{
if (parameters == null)
{
if (isFinal)
throw new Exception($"Operation {Text} must have parameters if final.");
return new ExpressionToken(first, this, last);
}
if (first != null)
throw new Exception($"Operation {Text} is unary.");
if (last == null)
throw new Exception($"Operation {Text} needs a variable.");
IToken evaluated = last.Evaluate(parameters, isFinal);
if (evaluated is ExpressionToken)
return new ExpressionToken(null, this, evaluated);
ListToken listToken = evaluated as ListToken;
if (listToken != null && listToken.Tokens.Exists(x => x is ExpressionToken))
return new ExpressionToken(null, this, evaluated);
string text = evaluated.Text;
TokenTreeList found = parameters.FindMatches(text, true);
ListToken result = new ListToken();
foreach (TokenTree tokenTree in found)
{
bool debug = bool.Parse(tokenTree["Debug"] ?? "False");
if (debug)
LogControl?.SetLogging(true);
IToken token = tokenTree.Value.Evaluate(parameters, isFinal);
if (!(token is NullToken))
result.Add(token);
if (debug)
LogControl?.ResetLoggingToDefault();
}
if (result.Tokens.Count == 0)
return new ExpressionToken(null, this, evaluated);
return result.Tokens.Count == 1 ? result.Tokens[0] : result;
}
示例5: Evaluate
public override IToken Evaluate(IToken first, IToken last, TokenTreeList parameters, bool isFinal)
{
if (_function == null)
{
if (first == null)
throw new Exception($"Operation {Text} can not be unary.");
IToken functionToken = first.Evaluate(parameters, isFinal);
if (functionToken == null || functionToken is ListToken)
throw new Exception($"First element of Operation {Text} is not unique.");
string function = functionToken.Text;
switch (function)
{
case AndFunction.ID:
_function = new AndFunction();
break;
case AggregateFunction.ID:
_function = new AggregateFunction();
break;
case CaseFunction.ID:
_function = new CaseFunction();
break;
case ComparisonFunction.ID:
_function = new ComparisonFunction();
break;
case ContainsFunction.ID:
_function = new ContainsFunction();
break;
case CountFunction.ID:
_function = new CountFunction();
break;
case DoubleFunction.ID:
_function = new DoubleFunction();
break;
case IfFunction.ID:
_function = new IfFunction();
break;
case IntFunction.ID:
_function = new IntFunction();
break;
case JoinFunction.ID:
_function = new JoinFunction();
break;
case OrFunction.ID:
_function = new OrFunction();
break;
case OverFunction.ID:
_function = new OverFunction();
break;
case RangeFunction.ID:
_function = new RangeFunction();
break;
case RegexFunction.ID:
_function = new RegexFunction();
break;
case ReverseFunction.ID:
_function = new ReverseFunction();
break;
case SplitFunction.ID:
_function = new SplitFunction();
break;
case SumFunction.ID:
_function = new SumFunction();
break;
case UserFunction.ID:
_function = new UserFunction();
break;
default:
ListToken newList = new ListToken
{
new ExpressionToken(null, new SubstitutionOperator(), new StringToken(function))
};
ListToken oldList = last.Evaluate(parameters, isFinal) as ListToken;
if (oldList != null)
{
foreach (IToken token in oldList.Tokens)
newList.Add(token);
}
else
{
newList.Add(last);
}
ExpressionToken expression = new ExpressionToken(null, new FunctionOperator(new UserFunction()), newList);
return expression.Evaluate(parameters, isFinal);
}
}
IToken parameterList;
if (isFinal && _function is UserFunction)
{
parameterList = PrepareUserFunction(last, parameters);
}
else if (_function.IsComparisonFunction)
{
parameterList = last.EvaluateList();
}
else
{
parameterList = last.Evaluate(parameters, !_function.FinalCanBeExpression && isFinal);
//.........这里部分代码省略.........
示例6: ProcessTokens
/// <summary>
/// Evaluates a token.
/// </summary>
/// <param name="value">The token to process.</param>
/// <param name="parameters">Calculation parameters.</param>
/// <returns>The processed token.</returns>
private static string ProcessTokens(IToken value, TokenTreeList parameters)
{
return value.Evaluate(parameters, false).Text;
}