public void SetUp ()
    {
      _leftExpression = Expression.Constant (1);
      _rightExpression = Expression.Constant (2);

      _expression = new SqlInExpression (_leftExpression, _rightExpression);
    }
Example #2
0
        public override Expression VisitConstant(ConstantExpression expression)
        {
            this.type = expression.Type;
            this.value = expression.Value;

            return expression;
        }
    public void SetUp ()
    {
      _stringExpression = Expression.Constant (0);
      _stringSequence = new[] { "a", "b", "c" };

      _dataWithCovariantSequence = new StreamedSequence (_stringSequence, new StreamedSequenceInfo (typeof (object[]), _stringExpression));
    }
        internal static Expression Replace(Expression expressionToAlter,
            ConstantExpression subExpressionToFind, Expression replacementExpression)
        {
            var visitor = new SubExpressionReplacer(subExpressionToFind, replacementExpression);

            return visitor.Visit(expressionToAlter);
        }
Example #5
0
        protected override Expression VisitConstant(ConstantExpression c)
        {
            if (c.Type == typeof(MethodInfo))
                _methodInfo = c.Value as MethodInfo;

            return base.VisitConstant(c);
        }
 protected override Expression VisitConstant(ConstantExpression c)
 {
     if (c.Type == typeof(JournalItemsContext<UAutoContractJournalItem>))
         return Expression.Constant(this.queryableJournalItems);
     else
         return c;
 }
 protected override Expression VisitConstant(ConstantExpression c) {
     if (c.Value is string)
         sb.AppendFormat("\"{0}\"", c.Value);
     else
         sb.Append(c.Value.ToString());
     return c;
 }
 public override void SetUp ()
 {
   base.SetUp ();
   _defaultValue = Expression.Constant (100);
   _nodeWithDefaultValue = new DefaultIfEmptyExpressionNode (CreateParseInfo (), _defaultValue);
   _nodeWithoutDefaultValue = new DefaultIfEmptyExpressionNode (CreateParseInfo (), null);
 }
 protected override Expression VisitConstant(ConstantExpression c)
 {
     IQueryable q = c.Value as IQueryable;
     if (q != null) {
         //throw new ApplicationException("Nested expressions not supported.");
     }
     else if (c.Value == null) {
         sb.Append("null");
     }
     else {
         if (c.Value.GetType() == typeof(Guid)) {
             sb.Append("'");
             sb.Append(c.Value);
             sb.Append("'");
         }
         else {
             switch (Type.GetTypeCode(c.Value.GetType())) {
                 case TypeCode.DateTime:
                     sb.Append("'");
                     sb.Append(((DateTime)c.Value).ToString("o"));
                     sb.Append("'");
                     break;
                 case TypeCode.Object:
                     throw new NotSupportedException(string.Format("The constant for '{0}' is not supported SimpleDB.", c.Value));
                 default:
                     sb.Append("'");
                     sb.Append(c.Value);
                     sb.Append("'");
                     break;
             }
         }
     }
     return c;
 }
 protected override Expression VisitConstant(ConstantExpression node)
 {
     var value = node.Value as int?;
     if (value.HasValue)
         return Expression.Constant(value + 1, node.Type);
     return base.VisitConstant(node);
 }
 protected override void establish_context()
 {
     base.establish_context();
     expression = Expression.Constant(this);
     rewriter = MockRepository.GenerateStub<IExpressionRewriter>();
     system_under_test.AddRewriter(rewriter);
 }
 protected virtual NamedValueExpression CreateNamedValueForConstant(ConstantExpression expression)
 {
     var name = "p" + (iParam++);
     var nv = new NamedValueExpression(name, expression);
     map.Add(GetKeyNameForConstantExpression(expression), new List<NamedValueExpression> { nv });
     return nv;
 }
        private static object EvaluateMemberAccessProperty(ConstantExpression node, PropertyInfo propertyAccessor)
        {
            var prop = node == null ? null : node.Value;
            var value = propertyAccessor.GetValue(prop, null);

            return ConvertMemberAccessValue(value);
        }
Example #14
0
 public static QueryProxyReference From(ConstantExpression cex)
 {
     return new QueryProxyReference
     {
         Type = XmlMetadataInfo.FromMetadata(cex.Type)
     };
 }
        protected override Expression VisitConstant(ConstantExpression constantExpression)
        {
            if (constantExpression.Value == null)
            {
                return base.VisitConstant(constantExpression);
            }

            var type = constantExpression.Value.GetType();

            switch (Type.GetTypeCode(type))
            {
                case TypeCode.Boolean:
                    if (Convert.ToBoolean(constantExpression.Value))
                    {
                        this.Write(this.ParameterIndicatorPrefix);
                        this.Write(ParamNamePrefix);
                        this.Write(this.parameterValues.Count);
                        this.parameterValues.Add(new Tuple<Type, object>(typeof(string), "true"));

                        return constantExpression;
                    }
                    else
                    {
                        this.Write(this.ParameterIndicatorPrefix);
                        this.Write(ParamNamePrefix);
                        this.Write(this.parameterValues.Count);
                        this.parameterValues.Add(new Tuple<Type, object>(typeof(string), "false"));

                        return constantExpression;
                    }
            }

            return base.VisitConstant(constantExpression);
        }
Example #16
0
			// See also e.g. Remotion.Linq.Clauses.ExpressionTreeVisitors.FormattingExpressionTreeVisitor
			// for another example of this technique.

			protected override Expression VisitConstantExpression(ConstantExpression expression)
			{
				if (expression.Value.IsProxy())
					return Expression.Parameter(expression.Type, ObjectHelpers.IdentityToString(expression.Value));

				return base.VisitConstantExpression(expression);
			}
        public void AddQueryPart(UnaryExpression leftItem, ConstantExpression rightValue, ExpressionType nodeType)
        {
            if(leftItem.Operand is MethodCallExpression)
            {
                var unaryOperation = (MethodCallExpression)leftItem.Operand;

                if(unaryOperation.Method.Name != "get_Item")
                {
                    throw new InvalidOperationException("Queries based on " + leftItem.Method.Name + " are not yet supported.");
                }

                if(unaryOperation.Arguments[0] is ConstantExpression)
                {
                    var attributeRef = ((ConstantExpression) unaryOperation.Arguments[0]).Value;
                    AddCriteriaToActiveSearchCondition(attributeRef.ToString(), rightValue.Value, GetSearchRelationType(nodeType));
                }
                else
                {
                    throw new InvalidOperationException("Only constant expressions are currently supported.");
                }

            }
            else
            {
                throw new InvalidOperationException("Queries based on " + leftItem.Method.Name + " are not yet supported.");
            }
        }
 protected override Expression VisitConstant(ConstantExpression node)
 {
     var visitor = new MemberExpressionVisitor(this.Context);
     visitor.Visit(node);
     Column = visitor.Column;
     return node;
 }
 protected override Expression VisitConstant(ConstantExpression c)
 {
     // have to do something here about type matching the types of Azure services
     if (c.Type == typeof(LinqToAzureOrderedQueryable<StorageAccount>) || c.Type == typeof(LinqToAzureOrderedQueryable<CloudService>))
         return Expression.Constant(_accounts);
     return c;
 }
Example #20
0
		protected override Expression VisitConstant(ConstantExpression constantExpression)
		{
			var type = constantExpression.Type;

			if ((this.options & SqlExpressionComparerOptions.IgnoreConstants) != 0)
			{
				return constantExpression;
			}

			if (type.IsValueType)
			{
				if (constantExpression.Value != null)
				{
					this.hashCode ^= constantExpression.Value.GetHashCode();
				}
			}
			else if (typeof(Expression).IsAssignableFrom(constantExpression.Type))
			{
				this.Visit((Expression)constantExpression.Value);
			}
			else if (type == typeof(string))
			{
				this.hashCode ^= constantExpression.Value?.GetHashCode() ?? 0;
			}

			return constantExpression;
		}
Example #21
0
        protected override Expression VisitConstant(ConstantExpression c)
        {
            if (disableQueryFilter)
                return base.VisitConstant(c);

            if (typeof(IQueryable).IsAssignableFrom(c.Type))
            {
                IQueryable query = (IQueryable)c.Value;

                if (query.IsBase())
                {
                    Type identType = c.Type.GetGenericArguments().SingleEx();

                    if (filter && Schema.Current.Tables.ContainsKey(identType))
                    {
                        IQueryable newQuery = miFilter.GetInvoker(identType)(Schema.Current, query);
                        
                        if (newQuery != query)
                            return newQuery.Expression;
                    }

                    return c;
                }
                else
                {
                    /// <summary>
                    /// Replaces every expression like ConstantExpression{ Type = IQueryable, Value = complexExpr } by complexExpr
                    /// </summary>
                    return DbQueryProvider.Clean(query.Expression, filter, null);
                }
            }

            return base.VisitConstant(c);
        }
Example #22
0
 protected override Expression VisitConstant(ConstantExpression c)
 {
     IQueryable q = c.Value as IQueryable;
     if (q != null)
     {
         _query.Index = q.ElementType.Name;
     }
     else if (c.Value == null)
     {
         //sb.Append("NULL");
     }
     else
     {
         switch (Type.GetTypeCode(c.Value.GetType()))
         {
             case TypeCode.Boolean:
                 //sb.Append(((bool)c.Value) ? 1 : 0);
                 break;
             case TypeCode.String:
     //                        sb.Append("'");
     //                        sb.Append(c.Value);
     //                        sb.Append("'");
                 break;
             case TypeCode.Object:
                 throw new NotSupportedException(string.Format("The constant for '{0}' is not supported", c.Value));
             default:
     //                        sb.Append(c.Value);
                 break;
         }
     }
     return c;
 }
        public static Expression ReplaceConstantsWithArrayIndexes(Expression node,
            ConstantExpression[] constantExpressions, ParameterExpression constantsParameter)
        {
            var visitor = new ConstantArrayIndexizerVisitor(constantExpressions, constantsParameter);

            return visitor.Visit(node);
        }
        protected override Expression VisitConstant(ConstantExpression c)
        {
            if (c.Type == queryType)
                return Expression.Constant(queryableContents);

            return c;
        }
        protected override Expression VisitConstant(ConstantExpression node)
        {
            if (node.Value is IQueryable)
                sourceQueryable = ((IQueryable)node.Value);

            return node;
        }
 protected override Expression VisitConstant(ConstantExpression constantExpression)
 {
     return constantExpression.Type.GetTypeInfo().IsGenericType
            && constantExpression.Type.GetGenericTypeDefinition() == typeof(EntityQueryable<>)
         ? VisitEntityQueryable(((IQueryable)constantExpression.Value).ElementType)
         : constantExpression;
 }
Example #27
0
        protected override Expression WalkConstant(ConstantExpression con)
        {
            var q = con.Value as IQueryable;
            if (q != null)
            {
                output.Append("SELECT * FROM ");
                output.Append(NameLookup.GetTableName(q.ElementType));
            }
            else if (con.Value == null)
            {
                output.Append("NULL");
            }
            else
            {

                switch (Type.GetTypeCode(con.Type))
                {
                    case TypeCode.Boolean: output.Append(((bool)con.Value) ? 1 : 0); break;
                    case TypeCode.String: output.AppendFormat("'{0}'", con.Value); break;
                    case TypeCode.DateTime: output.AppendFormat("'{0:dd-MM-yyyy HH:mm:ss}'", con.Value); break;
                    case TypeCode.Object: throw new UnsupportedQueryException(string.Format("Can't handle '{0}' constant in expression", con));
                    default:
                        output.Append(con.Value); break;
                }
            }
            return con;
        }
Example #28
0
 private string ConvertEntityRef(ConstantExpression expression)
 {
     FieldInfo field = expression.Value.GetType().GetFields().First();
     object value = field.GetValue(expression.Value);
     this.Parameters.Add(value);
     return "?";
 }
Example #29
0
        public static ConstantUpdate Create(PropertyInfo property, ConstantExpression constantExpr)
        {
            Debug.Assert(property != null, "property should not be null");
            Debug.Assert(constantExpr != null, "constantExpr should not be null");

            return new ConstantUpdate(property, constantExpr.Value);
        }
        protected override System.Linq.Expressions.Expression VisitConstant(ConstantExpression c)
        {
            switch(Type.GetTypeCode(c.Value.GetType()))
            {
                case TypeCode.Boolean:
                    _sb.Append(((bool)c.Value) ? "Value=\"True\"" : " Value=\"False\"");
                    break;
                case TypeCode.String:
                    _sb.Append(" Value=\"");
                    _sb.Append(c.Value);
                    _sb.Append("\"");
                    break;
                case TypeCode.Object:
                    throw new NotSupportedException(string.Format("The constant for '{0}' is not supported", c.Value));
                default:
                    _sb.Append(c.Value);
                    break;
            }



            //if (!string.IsNullOrEmpty(currentMember)) {
            //    sb.Append("</");
            //    sb.Append(currentMember);
            //    sb.Append(">");
            //    currentMember = string.Empty;
            //}               

            return c;
        }
 protected override System.Linq.Expressions.Expression VisitConstant(System.Linq.Expressions.ConstantExpression node)
 {
     if (constantFields.ContainsKey(node))
     {
         string fieldName = constantFields[node];
         return(Expression.Field(null, constantFieldStorageType, fieldName));
     }
     return(node);
 }
Example #32
0
        /// <summary>
        /// 表达式路由
        /// </summary>
        /// <param name="exp"></param>
        /// <returns></returns>
        string ExpressionRouter(System.Linq.Expressions.Expression exp)
        {
            //获取实体列的特性
            List <EntityPropColumnAttributes> columnAttrList = AttributeHelper.GetEntityColumnAtrributes <TEntity>();

            string sb = string.Empty;

            if (exp is System.Linq.Expressions.BinaryExpression)//二元运算符
            {
                System.Linq.Expressions.BinaryExpression be = ((System.Linq.Expressions.BinaryExpression)exp);
                return(BinarExpressionProvider(be.Left, be.Right, be.NodeType));
            }
            else if (exp is System.Linq.Expressions.MemberExpression)//成员
            {
                System.Linq.Expressions.MemberExpression me = ((System.Linq.Expressions.MemberExpression)exp);
                return(me.Member.Name);
            }
            else if (exp is System.Linq.Expressions.NewArrayExpression)//数组
            {
                System.Linq.Expressions.NewArrayExpression ae = ((System.Linq.Expressions.NewArrayExpression)exp);
                StringBuilder tmpstr = new StringBuilder();
                foreach (System.Linq.Expressions.Expression ex in ae.Expressions)
                {
                    tmpstr.Append(ExpressionRouter(ex));
                    tmpstr.Append(",");
                }
                return(tmpstr.ToString(0, tmpstr.Length - 1));
            }
            else if (exp is System.Linq.Expressions.MethodCallExpression)//方法
            {
                return(MethodExpression(exp));
            }
            else if (exp is System.Linq.Expressions.ConstantExpression)
            {
                System.Linq.Expressions.ConstantExpression ce = ((System.Linq.Expressions.ConstantExpression)exp);
                if (ce.Value == null)
                {
                    return("null");
                }
                else if (ce.Value is ValueType)
                {
                    return(ce.Value.ToString());
                }
                else if (ce.Value is string || ce.Value is DateTime || ce.Value is char)
                {
                    //return string.Format("'{0}'", ce.Value.ToString());
                    return(string.Format("{0}", ce.Value.ToString()));
                }
            }
            else if (exp is System.Linq.Expressions.UnaryExpression)
            {
                System.Linq.Expressions.UnaryExpression ue = ((System.Linq.Expressions.UnaryExpression)exp);
                return(ExpressionRouter(ue.Operand));
            }
            return(null);
        }
Example #33
0
        public Expression Parse(Linq.Expression linqExpression)
        {
            if (linqExpression is Linq.ConstantExpression)
            {
                Linq.ConstantExpression cexpr = (Linq.ConstantExpression)linqExpression;

                if (!(cexpr.Value is double))
                {
                    throw new Exception("Can't parse a non-numeric constant");
                }

                return(new NumberExpression((double)cexpr.Value));
            }
            else if (linqExpression is Linq.ParameterExpression)
            {
                Linq.ParameterExpression pexpr = (Linq.ParameterExpression)linqExpression;
                return(new VariableExpression(pexpr.Name));
            }
            else if (linqExpression is Linq.MethodCallExpression)
            {
                Linq.MethodCallExpression mexpr = (Linq.MethodCallExpression)linqExpression;

                IList <Expression> arguments = new List <Expression>();

                foreach (Linq.Expression arg in mexpr.Arguments)
                {
                    arguments.Add(Parse(arg));
                }

                if (!exists(mexpr.Method))
                {
                    throw new Exception("Method name doesn't exist in the scope");
                }

                if (mexpr.Method.Equals(powMethod))
                {
                    return(new BinaryExpression(Binary.Power, arguments[0], arguments[1]));
                }

                string name = get(mexpr.Method);

                return(new FunctionExpression(name, arguments));
            }
            else if (linqExpression is Linq.BinaryExpression)
            {
                Linq.BinaryExpression bexpr = (Linq.BinaryExpression)linqExpression;

                Expression left  = Parse(bexpr.Left);
                Expression right = Parse(bexpr.Right);

                return(new BinaryExpression(getOperator(bexpr.NodeType), left, right));
            }

            throw new Exception("Can't parse expression");
        }
Example #34
0
        static void Main(string[] args)
        {
            System.Console.WriteLine("Hello World!");
            Func <int, bool> test = i => i == 5;

            Expressions.ConstantExpression constExpr = Expressions.Expression.Constant(5, typeof(int));

            System.Console.WriteLine(constExpr.NodeType);
            System.Console.WriteLine(constExpr.Type);
            System.Console.WriteLine(constExpr.Value);
        }
            protected override SystemLinq.Expression VisitConstant(SystemLinq.ConstantExpression node)
            {
                var type  = node.Type;
                var value = node.Value;

                RemoteLinq.ConstantExpression exp;
                if (type is not null && typeof(SystemLinq.Expression).IsAssignableFrom(type) && value is SystemLinq.Expression expressionValue)
                {
                    var expValue = Visit(expressionValue).Unwrap();
                    exp = new RemoteLinq.ConstantExpression(expValue, _typeInfoProvider.GetTypeInfo(type));
                }
Example #36
0
        /// <summary>
        /// 执行翻译工作
        /// </summary>
        /// <param name="expr"></param>
        /// <param name="dbTranslator"></param>
        /// <param name="sBuilder"></param>
        /// <param name="dpc"></param>
        private void parse(Expression expr, IDbTranslator dbTranslator, StringBuilder sBuilder, DataParameterCollection dpc)
        {
            if (expr is BinaryExpression)
            {
                //翻译二元运算符表达式
                this.parseBinaryExpression((BinaryExpression)expr, dbTranslator, sBuilder, dpc);
            }
            else if (expr is UnaryExpression)
            {
                //翻译一元运算符的表达式
                this.parseUnaryExpression((UnaryExpression)expr, dbTranslator, sBuilder, dpc);
            }
            else if (expr is MethodCallExpression)
            {
                //翻译对静态方法或实例方法的调用
                this.parseMethodCallExpression((MethodCallExpression)expr, dbTranslator, sBuilder, dpc);
            }
            else if (expr is System.Linq.Expressions.ConstantExpression)
            {
                System.Linq.Expressions.ConstantExpression cExp = expr as System.Linq.Expressions.ConstantExpression;

                bool cExpValue = false;
                if (cExp.Value != null)
                {
                    if (!bool.TryParse(cExp.Value.ToString(), out cExpValue))
                    {
                        cExpValue = true;
                    }
                }
                if (cExpValue)
                {
                    sBuilder.Append("(1=1)");
                }
                else
                {
                    sBuilder.Append("(1<>1)");
                }
            }
            else
            {
                if (isBooleanFieldOrProperty(expr))
                {
                    IPropertyMapper propertyMapper = this.getPropertyMapper(((MemberExpression)expr).Member.Name);
                    //生成SQL片段和参数
                    this.buildSqlAndDataParameter(propertyMapper, ColumnFunction.None, CompareOpration.Equal, true, dbTranslator, sBuilder, dpc);
                }
                else
                {
                    throw new MapleException("该操作不支持!" + expr.Type.FullName);
                }
            }
        }
 protected override System.Linq.Expressions.Expression VisitConstant(System.Linq.Expressions.ConstantExpression node)
 {
     if (!CanEmitILConstant(node.Type) && node.Value != null)
     {
         if (!constantFields.ContainsKey(node))
         {
             string name = "const" + constantFields.Count;
             constantFields[node] = name;
             constantFieldStorageType.DefineField(name, node.Type, FieldAttributes.Public | FieldAttributes.Static);
         }
     }
     return(node);
 }
Example #38
0
            private Expression Convert(LinqExp.ConstantExpression linqConstant)
            {
                switch (linqConstant.Value)
                {
                case Expression dlrExpression:
                    return(dlrExpression);

                case LinqExp.Expression linqExpression:
                    return(ConvertExp(linqExpression));

                default:
                    return(Expression.Constant(linqConstant.Value, linqConstant.Type));
                }
            }
Example #39
0
 protected override System.Linq.Expressions.Expression VisitConstant(System.Linq.Expressions.ConstantExpression c)
 {
     // Ef cannot map enumerations to the database, we need to use ints instead
     if (c.Value != null && c.Type.IsEnum) // Handle Enums
     {
         return(Expression.Constant((int)c.Value, typeof(int)));
     }
     else if (c.Value != null && c.Type.IsGenericType && c.Type.GetGenericTypeDefinition() == typeof(Nullable <>) && c.Type.GetGenericArguments().Single().IsEnum)
     {
         return(Expression.Constant((int)c.Value, typeof(int?))); // You can't extract a int? from an enum value
     }
     else
     {
         return(base.VisitConstant(c));
     }
 }
Example #40
0
        internal DebugInfoRewriter(
            DebugContext debugContext,
            bool transformToGenerator,
            MSAst.Expression traceLocations,
            MSAst.Expression thread,
            MSAst.Expression frame,
            MSAst.Expression pushFrame,
            MSAst.Expression debugMarker,
            MSAst.Expression globalDebugMode,
            Dictionary <DebugSourceFile, MSAst.ParameterExpression> sourceFilesToVariablesMap,
            MSAst.LabelTarget generatorLabel,
            Dictionary <MSAst.ParameterExpression, MSAst.ParameterExpression> replacedLocals,
            Dictionary <MSAst.ParameterExpression, VariableInfo> localsToVarInfos,
            DebugLambdaInfo lambdaInfo)
        {
            _debugContext         = debugContext;
            _transformToGenerator = transformToGenerator;
            _traceLocations       = traceLocations;
            _thread    = thread;
            _frame     = frame;
            _pushFrame = pushFrame;

            if (_transformToGenerator)
            {
                _debugYieldValue = Ast.Constant(DebugContext.DebugYieldValue);

                // When transforming to generator we'll also create marker-location and position-handler maps
                _markerLocationMap     = new Dictionary <int, DebugSourceSpan>();
                _variableScopeMap      = new Dictionary <int, IList <VariableInfo> >();
                _currentLocals         = new Stack <MSAst.BlockExpression>();
                _variableScopeMapCache = new Dictionary <MSAst.BlockExpression, IList <VariableInfo> >();
            }

            _debugMarker               = debugMarker;
            _globalDebugMode           = globalDebugMode;
            _sourceFilesToVariablesMap = sourceFilesToVariablesMap;
            _generatorLabelTarget      = generatorLabel;
            _replacedLocals            = replacedLocals;
            _localsToVarInfos          = localsToVarInfos;
            _lambdaInfo = lambdaInfo;
        }
Example #41
0
        private SqlExpression ParseConstant(System.Linq.Expressions.ConstantExpression constant)
        {
            switch (constant.Value)
            {
            case char ch:
                return(new SqlConstantExpression(FieldType.Char, ch));

            case string str:
                return(new SqlConstantExpression(FieldType.String, str));

            case int i:
                return(new SqlConstantExpression(FieldType.Int, i));

            case double d:
                return(new SqlConstantExpression(FieldType.Double, d));

            case bool b:
                return(new SqlConstantExpression(FieldType.Bool, b));
            }
            throw new NotImplementedException();
        }
 private static Expression Convert(LinqExp.ConstantExpression linqConstant)
 => Expression.Constant(linqConstant.Value, linqConstant.Type);
Example #43
0
 /// <summary>
 /// Visits the <see cref="ConstantExpression"/>.
 /// </summary>
 /// <param name="node">The expression to visit.</param>
 /// <returns>The modified expression, if it or any subexpression was modified;
 /// otherwise, returns the original expression.</returns>
 protected internal virtual Expression VisitConstant(ConstantExpression node)
 {
     return(node);
 }
Example #44
0
 protected internal override Expression VisitConstant(ConstantExpression node)
 {
     Out(Constant(node.Value));
     return(node);
 }
 protected override Expression VisitConstant(ConstantExpression node) => MakeBinding(node);
 public ConstantExpressionProxy(ConstantExpression node)
 {
     ContractUtils.RequiresNotNull(node, nameof(node));
     _node = node;
 }
Example #47
0
 protected virtual Expression VisitConstant(ConstantExpression node)
 {
     throw new NotImplementedException();
 }
 protected virtual void VisitConstant(ConstantExpression constant)
 {
 }
Example #49
0
            protected override string VisitConstant(ConstantExpression node)
            {
                var value = node.Value != null?node.Value.ToString() : "null";

                return("(" + GetType(node.Type) + ")" + value);
            }
Example #50
0
        protected internal override Expression VisitConstant(ConstantExpression node)
        {
            var value = node.Value;

            switch (value)
            {
            case null:
                Out("null");
                break;

            case string _ when node.Type == typeof(string):
                Out
                (
                    string.Format
                    (
                        CultureInfo.CurrentCulture,
                        "\"{0}\"",
                        value
                    )
                );
                break;

            case char _ when node.Type == typeof(char):
                Out
                (
                    string.Format
                    (
                        CultureInfo.CurrentCulture,
                        "'{0}'",
                        value
                    )
                );
                break;

            case int _ when node.Type == typeof(int):
            case bool _ when node.Type == typeof(bool):
                Out(value.ToString());
                break;

            default:
                var suffix = GetConstantValueSuffix(node.Type);
                if (suffix != null)
                {
                    Out(value.ToString());
                    Out(suffix);
                }
                else
                {
                    Out
                    (
                        string.Format
                        (
                            CultureInfo.CurrentCulture,
                            ".Constant<{0}>({1})",
                            node.Type.ToString(),
                            value
                        )
                    );
                }

                break;
            }

            return(node);
        }
Example #51
0
 protected override System.Linq.Expressions.Expression VisitConstantExpression(System.Linq.Expressions.ConstantExpression expression)
 {
     return(Expression.Constant("ConstantExpression was visited"));
 }
Example #52
0
 /// <summary>
 /// There is never a constant reference, so don't let it go!
 /// </summary>
 /// <param name="expr"></param>
 /// <param name="codeEnv"></param>
 /// <param name="context"></param>
 /// <param name="container"></param>
 /// <returns></returns>
 public IValue ProcessConstantReference(System.Linq.Expressions.ConstantExpression expr, IGeneratedQueryCode codeEnv, CompositionContainer container)
 {
     throw new NotImplementedException();
 }
Example #53
0
        private static SysLE.Expression SysExpressionWhere_Analyize(SysLE.Expression exp, StringBuilder builder)
        {
            if (exp == null)
            {
                return(null);
            }

            SysLE.BinaryExpression binEx = exp as SysLE.BinaryExpression;
            if (binEx != null)
            {
                SysExpressionWhere_Analyize(binEx.Left, builder);
            }

            switch (exp.NodeType)
            {
            case SysLE.ExpressionType.Parameter:
            {
                SysLE.ParameterExpression param = (SysLE.ParameterExpression)exp;
                builder.Append("(" + param.Name);
                return(null);
            }

            case SysLE.ExpressionType.MemberAccess:
            {
                SysLE.MemberExpression mexp = (SysLE.MemberExpression)exp;
                builder.Append("(" + mexp.Member.Name);
                return(null);
            }

            case SysLE.ExpressionType.Constant:
            {
                SysLE.ConstantExpression cex = (SysLE.ConstantExpression)exp;
                if (cex.Value is string)
                {
                    builder.Append("'" + cex.Value.ToString() + "') ");
                }
                else
                {
                    builder.Append(cex.Value.ToString() + ")");
                }
                return(null);
            }

            default:
            {
                if (exp.NodeType == SysLE.ExpressionType.Equal)
                {
                    builder.Append("=");
                }
                else if (exp.NodeType == SysLE.ExpressionType.NotEqual)
                {
                    builder.Append("<>");
                }
                else if (exp.NodeType == SysLE.ExpressionType.LessThan)
                {
                    builder.Append("<");
                }
                else if (exp.NodeType == SysLE.ExpressionType.LessThanOrEqual)
                {
                    builder.Append("<=");
                }
                else if (exp.NodeType == SysLE.ExpressionType.GreaterThan)
                {
                    builder.Append(">");
                }
                else if (exp.NodeType == SysLE.ExpressionType.GreaterThanOrEqual)
                {
                    builder.Append(">=");
                }
                else if (exp.NodeType == SysLE.ExpressionType.AndAlso || exp.NodeType == SysLE.ExpressionType.And)
                {
                    builder.Append("and");
                }
                else if (exp.NodeType == SysLE.ExpressionType.OrElse || exp.NodeType == SysLE.ExpressionType.Or)
                {
                    builder.Append("or");
                }
            }
            break;
            }

            if (binEx != null)
            {
                SysExpressionWhere_Analyize(binEx.Right, builder);
            }

            return(binEx);
        }
Example #54
0
 protected virtual ConstantExpression VisitConstant(ConstantExpression constant)
 {
     return(constant);
 }
Example #55
0
 protected virtual bool VisitConstant(ConstantExpression c, ConstantExpression c2)
 {
     return(Equals(c.Value, c2.Value));
 }
Example #56
0
 internal virtual Expression VisitConstant(ConstantExpression c)
 {
     return((Expression)c);
 }
Example #57
0
        private int DoFilterData()
        {
            var filterData = GetFilterData();

            foreach (var singleFilter in filterData)
            {
                var dataKey   = singleFilter.Field;
                var dataOp    = singleFilter.Comparison;
                var dataValue = singleFilter.Data;

                Linq.Expression <Func <T, bool> > wherePredicate;

                if (_filterActions.ContainsKey(dataKey.ToLower()))
                {
                    wherePredicate = _filterActions[dataKey.ToLower()].Invoke(dataValue);
                }
                else if (dataKey.Contains("-date-range-"))
                {
                    var param    = Linq.Expression.Parameter(typeof(T), "x");
                    var propName = dataKey.Substring(0, dataKey.IndexOf("-date-range-", 0));
                    var property = BuildPropertyExpression(param, propName);

                    Linq.ConstantExpression filter = Linq.Expression.Constant
                                                     (
                        ChangeType(dataValue, property.Type), property.Type
                                                     );
                    Linq.BinaryExpression condition;
                    if (dataKey.Contains("-date-range-start"))
                    {
                        condition = Linq.Expression.GreaterThanOrEqual(property, filter);
                    }
                    else
                    {
                        if (filter.Type == typeof(DateTimeOffset))
                        {
                            filter = Linq.Expression.Constant(((DateTimeOffset)filter.Value).AddDays(1), property.Type);
                        }
                        else
                        {
                            filter = Linq.Expression.Constant(((DateTime)filter.Value).AddDays(1), property.Type);
                        }

                        condition = Linq.Expression.LessThan(property, filter);
                    }
                    wherePredicate = Linq.Expression.Lambda <Func <T, bool> >(condition, param);
                }
                else if (dataOp == ComparisonOperator.@in)
                {
                    var param          = Linq.Expression.Parameter(typeof(T), "x");
                    var property       = BuildPropertyExpression(param, dataKey);
                    var collectionType = typeof(ICollection <>).MakeGenericType(property.Type);
                    var collectionData = JsonConvert.DeserializeObject(dataValue, collectionType);
                    var method         = collectionType.GetMethod("Contains", new[] { property.Type });
                    var value          = Linq.Expression.Constant(collectionData, collectionType);
                    var condition      = Linq.Expression.Call(value, method, property);

                    wherePredicate = Linq.Expression.Lambda <Func <T, bool> >(condition, param);
                }
                else
                {
                    var param    = Linq.Expression.Parameter(typeof(T), "x");
                    var property = BuildPropertyExpression(param, dataKey);
                    var value    = Linq.Expression.Constant(ChangeType(dataValue, property.Type), property.Type);
                    if (dataOp == ComparisonOperator.cn && property.Type != typeof(string))
                    {
                        dataOp = ComparisonOperator.eq;
                    }

                    var contains   = typeof(string).GetMethod("Contains", new Type[] { typeof(string) });
                    var startsWith = typeof(string).GetMethod("StartsWith", new Type[] { typeof(string) });
                    var endsWith   = typeof(string).GetMethod("EndsWith", new Type[] { typeof(string) });

                    Linq.Expression condition;
                    switch (dataOp)
                    {
                    case ComparisonOperator.eq:
                        condition = Linq.Expression.Equal(property, value);
                        break;

                    case ComparisonOperator.ne:
                        condition = Linq.Expression.NotEqual(property, value);
                        break;

                    case ComparisonOperator.lt:
                        condition = Linq.Expression.LessThan(property, value);
                        break;

                    case ComparisonOperator.le:
                        condition = Linq.Expression.LessThanOrEqual(property, value);
                        break;

                    case ComparisonOperator.gt:
                        condition = Linq.Expression.GreaterThan(property, value);
                        break;

                    case ComparisonOperator.ge:
                        condition = Linq.Expression.GreaterThanOrEqual(property, value);
                        break;

                    case ComparisonOperator.bw:
                        condition = Linq.Expression.Call(property, startsWith, value);
                        break;

                    case ComparisonOperator.bn:
                        condition = Linq.Expression.Not(Linq.Expression.Call(property, startsWith, value));
                        break;

                    case ComparisonOperator.ni:
                        condition = Linq.Expression.Not(Linq.Expression.Call(value, contains, property));
                        break;

                    case ComparisonOperator.ew:
                        condition = Linq.Expression.Call(property, endsWith, value);
                        break;

                    case ComparisonOperator.en:
                        condition = Linq.Expression.Not(Linq.Expression.Call(property, endsWith, value));
                        break;

                    case ComparisonOperator.cn:
                        condition = Linq.Expression.Call(property, contains, value);
                        break;

                    case ComparisonOperator.nc:
                        condition = Linq.Expression.Not(Linq.Expression.Call(property, contains, value));
                        break;

                    default:
                        condition = Linq.Expression.Equal(property, value);
                        break;
                    }
                    wherePredicate = Linq.Expression.Lambda <Func <T, bool> >(condition, param);
                }
                _queryable = _queryable.Where(wherePredicate);
            }
            return(_queryable.Count());
        }