private static object ParseMemberAccessExpression(Expression operation)
        {
            MemberExpression me = (MemberExpression)operation;

            if (me.Expression.Type == typeof(Model.Attribute))
            {
                return(ElementParser.ParseAttribute(me));
            }

            //Don't execute properties defined on internal objects
            if (me.Member.Module.Assembly.FullName == typeof(LambdaExpressionParser).Assembly.FullName)
            {
                return(operation);
            }

            //Evaluate values of variables/properties
            object instance = ParseSubExpressions(me.Expression);

            if (instance != null)
            {
                var retValue = ElementParser.ResolveFieldOrProperty(me, instance);

                if (retValue is string)
                {
                    return(new ExpressionTerm()
                    {
                        Value = retValue.ToString()
                    });
                }

                return(retValue);
            }

            return(operation.ToString());
        }
        private static object CallMethod(Expression operation)
        {
            MethodCallExpression me = (MethodCallExpression)operation;

            var mex = me.Object as MemberExpression;

            if (mex != null && mex.Member != null && (mex.Member.Name == "TargetElementText" || mex.Member.Name == "Text"))
            {
                string textFunction = "TargetElementText";

                if (mex.Member.Name == "Text")
                {
                    textFunction = "Parent.Text";
                }

                var text = Expression.Lambda(me.Arguments[0]).Compile().DynamicInvoke().ToString();
                return(new ExpressionTerm()
                {
                    Value = text, Function = textFunction, FunctionArgument = me.Method.Name
                });
            }

            if (me.Object != null && me.Object.Type == typeof(Model.Attribute))
            {
                return(ElementParser.ParseAttribute(me));
            }

            return(new ExpressionTerm()
            {
                Value = InvokeExpression(me).ToString()
            });
        }
 public static void Parse(Element element, ExpressionTerm expressionTerm)
 {
     foreach (var parser in ElementParser.GetAllParsers())
     {
         bool done = parser(element, expressionTerm);
         if (done == true)
         {
             return;
         }
     }
 }
예제 #4
0
        public static List <Func <Element, ExpressionTerm, bool> > GetAllParsers()
        {
            List <Func <Element, ExpressionTerm, bool> > parsers = new List <Func <Element, ExpressionTerm, bool> >();

            parsers.Add((element, expressionTerm) => ElementParser.ParseParent(element, expressionTerm));
            parsers.Add((element, expressionTerm) => ElementParser.ParseContextElement(element, expressionTerm));
            parsers.Add((element, expressionTerm) => ElementParser.ParseSiblings(element, expressionTerm));
            parsers.Add((element, expressionTerm) => ElementParser.ParsePosition(element, expressionTerm));
            parsers.Add((element, expressionTerm) => ElementParser.ParseRelatives(element, expressionTerm));

            return(parsers);
        }
        public static void ParseExpression(BinaryExpression chain, Element element)
        {
            ElementParser.ThrowIfNotSupported(chain);

            if (chain.Left is BinaryExpression)
            {
                Parse(element, (ExpressionTerm)ParseSubExpressions(chain.Right));
                ParseExpression((BinaryExpression)chain.Left, element);
            }
            else
            {
                ExpressionTerm expressionTerm = (ExpressionTerm)ParseSubExpressions(chain.Right);
                expressionTerm.Function = chain.Left.ToString();
                Parse(element, expressionTerm);
            }
        }