本文整理汇总了C#中IParserContext.CreateLocal方法的典型用法代码示例。如果您正苦于以下问题:C# IParserContext.CreateLocal方法的具体用法?C# IParserContext.CreateLocal怎么用?C# IParserContext.CreateLocal使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IParserContext
的用法示例。
在下文中一共展示了IParserContext.CreateLocal方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Evaluate
public override ValueExpression Evaluate(IParserContext context)
{
IEnumerable collection = Expression.Evaluate(context).Value as IEnumerable;
if (collection != null)
foreach (var item in collection)
{
var localContext = context.CreateLocal();
localContext.Set(Iterator.VarName, item);
var returnValue = Body.Evaluate(localContext);
if (returnValue is ReturnValueExpression)
{
return returnValue;
}
}
return Exp.NullValue(TokenPosition);
}
示例2: Evaluate
public override ValueExpression Evaluate(IParserContext context)
{
object methodObject = MethodExpression.Evaluate(context).Value;
ValueExpression[] parameters = EvaluateExpressionArray(Parameters, context);
Type[] parameterTypes = parameters.ConvertAll(expr => expr.Type);
object[] parameterValues = parameters.ConvertAll(expr => expr.Value);
if (methodObject is MethodDefinition)
{
Type returnType;
return Exp.Value(TokenPosition, ((MethodDefinition)methodObject).Invoke(parameterTypes, parameterValues, out returnType), returnType);
}
if (methodObject is ConstructorInfo[])
{
ConstructorInfo[] constructors = (ConstructorInfo[]) methodObject;
MethodBase method = LazyBinder.SelectBestMethod(constructors, parameterTypes, BindingFlags.Public | BindingFlags.Static | BindingFlags.Instance);
if (method == null)
throw new ExpressionEvaluationException("No match found for constructor " + constructors[0].Name, this);
object value = LazyBinder.Invoke(method, parameterValues);
//object value = ((ConstructorInfo)method).Invoke(parameterValues);
return Exp.Value(TokenPosition, value, method.DeclaringType);
}
if (methodObject is Delegate[])
{
Delegate[] delegates = (Delegate[]) methodObject;
MethodBase[] methods = delegates.ConvertAll<Delegate, MethodBase>(d => d.GetMethodInfo());
MethodBase method = LazyBinder.SelectBestMethod(methods, parameterTypes, BindingFlags.Public | BindingFlags.Static | BindingFlags.Instance);
if (method == null)
throw new ExpressionEvaluationException("No match found for delegate " + MethodExpression, this);
object value = LazyBinder.Invoke(method, delegates[Array.IndexOf(methods, method)].Target, parameterValues);
return Exp.Value(TokenPosition, value, ((MethodInfo)method).ReturnType);
}
if (methodObject is Delegate)
{
Delegate method = (Delegate) methodObject;
MethodInfo methodInfo = method.GetMethodInfo();
object value = methodInfo.Invoke(method.Target, parameterValues);
return new ValueExpression(TokenPosition, value, methodInfo.ReturnType);
}
if (methodObject is FunctionDefinitionExpression)
{
FunctionDefinitionExpression func = (FunctionDefinitionExpression) methodObject;
var functionContext = context.CreateLocal();
for (int i=0;i<parameterValues.Length;i++)
{
functionContext.Set(func.ParameterNames[i],parameterValues[i]);
}
return func.Body.Evaluate(functionContext);
}
throw new ExpressionEvaluationException(MethodExpression + " is not a function", this);
}