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


C# IParserContext.CreateLocal方法代码示例

本文整理汇总了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);
        }
开发者ID:TheMouster,项目名称:core,代码行数:21,代码来源:ForEachExpression.cs

示例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);
        }
开发者ID:TheMouster,项目名称:core,代码行数:72,代码来源:CallExpression.cs


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