Esempio n. 1
0
 private static ParsedExpression VisitBinary(BinaryExpression node, CsmQueryOperator opr)
 {
     var pe = new ParsedExpression
     {
         Property = VisitExpression(node.Left).Property,
         Value = VisitExpression(node.Right, true).Value,
         Operator = opr
     };
     return pe;
 }
Esempio n. 2
0
        private static ParsedExpression VisitMember(MemberExpression node, bool valueExpression = false)
        {
            var pe = new ParsedExpression();
            if (node.Member is PropertyInfo && !valueExpression)
            {
                if (node.Expression is MemberExpression)
                {
                    pe.Property = ((MemberExpression)node.Expression).Member.Name + "." + ((PropertyInfo)node.Member).GetName();
                }
                else
                {
                    pe.Property = ((PropertyInfo)node.Member).GetName();
                }

                return pe;
            }

            if (node.Expression is ConstantExpression)
            {
                var memConst = (ConstantExpression)node.Expression;
                pe.Value = ((FieldInfo)node.Member).GetValue(memConst.Value).ToString();

                return pe;
            }

            var memberConst = (MemberExpression)node.Expression;
            var captureConst = (ConstantExpression)memberConst.Expression;
            var fieldValue = ((FieldInfo) memberConst.Member).GetValue(captureConst.Value);
            var propValue = ((PropertyInfo) node.Member).GetValue(fieldValue);

            if (propValue == null)
            {
                throw new NotSupportedException("Null is not supported at this time");
            }

            pe.Value = propValue.ToString();

            return pe;
        }