Exemplo n.º 1
0
 protected override Expression VisitUnary(UnaryExpression node)
 {
     return Expression.MakeUnary(
         node.NodeType,
         Visit(node.Operand),
         node.Type);
 }
		protected override Expression VisitUnary(UnaryExpression unaryExpression)
		{
			if (unaryExpression.NodeType == ExpressionType.Not && unaryExpression.Type.GetUnwrappedNullableType() == typeof(bool))
			{
				var operand = this.Visit(unaryExpression.Operand);

				if (operand is BitBooleanExpression)
				{
					return Expression.MakeUnary(unaryExpression.NodeType, Expression.Equal(operand, Expression.Constant(true, operand.Type)), typeof(bool));
				}
			}
			else if (unaryExpression.NodeType == ExpressionType.Convert
				&& unaryExpression.Type.GetUnwrappedNullableType() == typeof(bool)
				&& unaryExpression.Operand.Type.GetUnwrappedNullableType() != typeof(bool))
			{
				var operand = this.Visit(unaryExpression.Operand);

				if (operand is BitBooleanExpression)
				{
					return Expression.MakeUnary(unaryExpression.NodeType, Expression.Equal(operand, Expression.Constant(true, operand.Type)), typeof(bool));
				}
			}

			return base.VisitUnary(unaryExpression);
		}
Exemplo n.º 3
0
        static Node ParseUnaryNot(UnaryExpression e)
        {
            string suffix = e.Operand is BinaryExpression ? ")" : null;
            string prefix = e.Operand is BinaryExpression ? "!(" : "!";

            return new UnaryNode { Prefix = prefix, Operand = Parse(e.Operand), PrefixValue = GetValue(e), Suffix = suffix };
        }
        protected override Expression VisitUnary(UnaryExpression node) {
            if (node.NodeType == ExpressionType.Convert) {
                return Expression.ConvertChecked(node.Operand, node.Type);
            }

            return base.VisitUnary(node);
        }
 protected override Expression VisitUnary(UnaryExpression node)
 {
     if (node.NodeType == ExpressionType.Not && node.Operand is MemberExpression)
     {
         return base.VisitUnary(node);
     }
     var exp = base.VisitUnary(node);
     if (node.NodeType == ExpressionType.Not)
     {
         string condition = _conditionStack.Pop();
         _conditionStack.Push("(NOT " + condition + ")");
     }
     else if (node.NodeType == ExpressionType.Convert)
     {
         if (node.Operand is ConstantExpression)
         {
             _constStack.Push((node.Operand as ConstantExpression).Value);
         }
     }
     else
     {
         throw new Exception("未支持一元操作符:" + node.NodeType.ToString());
     }
     return exp;
 }
Exemplo n.º 6
0
 internal static Quote Quote(UnaryExpression expression)
 {
     return new Quote()
     {
         Operand = Serialize(expression.Operand),
     }.Apply(n => n.Type = TypeRef.Serialize(expression.Type));
 }
Exemplo n.º 7
0
 private static SqlExpression VisitConvert(UnaryExpression expression)
 {
     if (expression.Operand.NodeType == ExpressionType.MemberAccess) {
         return VisitMemberAccess((MemberExpression)expression.Operand);
     }
     throw new NotImplementedException();
 }
 protected override Expression VisitUnary(UnaryExpression u)
 {
     throw new NotSupportedException(
         string.Format(
             "The unary operator '{0}' is not supported",
             u.NodeType));
 }
Exemplo n.º 9
0
            protected override Expression VisitUnary(UnaryExpression node)
            {
                switch (node.NodeType)
                {
                    case ExpressionType.Not:
                        if (node.Operand is SubQueryExpression)
                        {
                            var nested = new WhereClauseVisitor(_parent, _mapping);
                            nested.Visit(node.Operand);

                            var @where = new NotWhereFragment(nested.ToWhereFragment());
                            _register.Peek()(@where);
                        }
                        else
                        {
                            var visitor = new NotVisitor(this, _mapping, _register.Peek());
                            visitor.Visit(node);
                        }

                        return null;
                }


                return base.VisitUnary(node);
            }
        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.");
            }
        }
Exemplo n.º 11
0
        protected override Expression VisitUnary(UnaryExpression node)
        {
            if (node.NodeType != ExpressionType.Convert && node.NodeType != ExpressionType.ConvertChecked)
            {
                return base.VisitUnary(node);
            }

            if (node.Operand.NodeType != ExpressionType.MemberAccess)
            {
                return base.VisitUnary(node);
            }

            if (!ReflectionHelper.IsNullable(node.Type))
            {
                return base.VisitUnary(node);
            }

            MemberExpression memberNode = node.Operand as MemberExpression;

            if (memberNode.Expression == null)
            {
                // Static member access cannot be rewritten
                return base.VisitUnary(node);
            }

            return this.CreateSafeMemberAccessExpression(node.Operand as MemberExpression, node.Type);
        }
Exemplo n.º 12
0
 private Expression ConvertCast(LinqExp.UnaryExpression linqConvert, Func <Expression, Type, MethodInfo, Expression> factory)
 {
     return(factory.Invoke(
                ConvertExp(linqConvert.Operand),
                linqConvert.Type,
                linqConvert.Method));
 }
Exemplo n.º 13
0
 internal static ArrayLength ArrayLength(UnaryExpression expression)
 {
     return new ArrayLength()
     {
         Operand = Serialize(expression.Operand),
     }.Apply(n => n.Type = TypeRef.Serialize(expression.Type));
 }
Exemplo n.º 14
0
        public static string GetPropertyName <TModel, TResult>(System.Linq.Expressions.Expression <Func <TModel, TResult> > property)
        {
            System.Linq.Expressions.LambdaExpression lambda = (System.Linq.Expressions.LambdaExpression)property;
            System.Linq.Expressions.MemberExpression memberExpression;

            if (lambda.Body is System.Linq.Expressions.UnaryExpression)
            {
                System.Linq.Expressions.UnaryExpression unaryExpression = (System.Linq.Expressions.UnaryExpression)(lambda.Body);
                memberExpression = (System.Linq.Expressions.MemberExpression)(unaryExpression.Operand);
            }
            else
            {
                memberExpression = (System.Linq.Expressions.MemberExpression)(lambda.Body);
            }
            string parent = "";

            if (typeof(TModel) != memberExpression.Expression.Type)  /// sub property // to do hierahly cycle
            {
                var submemember = memberExpression.Expression as System.Linq.Expressions.MemberExpression;
                if (submemember != null)
                {
                    parent = submemember.Member.Name + ".";
                }
            }

            return(parent + ((PropertyInfo)memberExpression.Member).Name);
        }
Exemplo n.º 15
0
        protected override Expression VisitUnary(UnaryExpression node)
        {
            base.VisitUnary(node);
            var filter = stack.Pop();

            if (node.NodeType == ExpressionType.Not)
            {
                stack.Push(new Ast.UnaryExpression
                {
                    Operator = JqlUnaryExpressionType.Not,
                    Operand  = filter
                });
            }
            else if (node.NodeType == ExpressionType.Convert)
            {
                stack.Push(filter);
            }
            else
            {
                throw new InvalidOperationException(
                          $"not supported unary operator [{node.NodeType}]");
            }

            return(node);
        }
Exemplo n.º 16
0
 protected override Expression VisitUnary(UnaryExpression u)
 {
     if (u.NodeType == ExpressionType.Quote)
     {
         return base.Visit(u.Operand);
     }
     return base.VisitUnary(u);
 }
Exemplo n.º 17
0
 internal static Unbox Unbox(UnaryExpression expression)
 {
     return new Unbox()
     {
         Operand = Serialize(expression.Operand),
         Type = TypeRef.Serialize(expression.Type),
     };
 }
Exemplo n.º 18
0
        //string GetColumnName(LambdaExpression member)
        //{
        //    var mbody = member.Body as MemberExpression;
        //    if (mbody != null) return GetColumnName(mbody);
        //    var ubody = member.Body as UnaryExpression;
        //    if (ubody == null) throw new NotSupportedException("Only members and unary expressions are supported");
        //    return GetColumnName(ubody);
        //}

        private string GetColumnName(UnaryExpression member)
        {
            var mbody = member.Operand as MemberExpression;
            if (mbody != null) return GetColumnName(mbody);
            var ubody = member.Operand as UnaryExpression;
            if (ubody != null) return GetColumnName(ubody);
            throw new NotSupportedException("Only members and unary expressions are supported");
        }
Exemplo n.º 19
0
 internal static PreDecrementAssign PreDecrementAssign(UnaryExpression expression)
 {
     return new PreDecrementAssign()
     {
         Operand = Serialize(expression.Operand),
         Method = expression.Method.Null(m => MethodRef.Serialize(m)),
     }.Apply(n => n.Type = TypeRef.Serialize(expression.Type));
 }
Exemplo n.º 20
0
        protected override Expression VisitUnary(UnaryExpression u)
        {
            u = (UnaryExpression)base.VisitUnary(u);
            if (u.NodeType != ExpressionType.Not)
                return u;

            return Invert(u.Operand, u);
        }
Exemplo n.º 21
0
 internal static OnesComplement OnesComplement(UnaryExpression expression)
 {
     return new OnesComplement()
     {
         Operand = Serialize(expression.Operand),
         Method = expression.Method.Null(m => MethodRef.Serialize(m)),
     }.Apply(n => n.Type = TypeRef.Serialize(expression.Type));
 }
Exemplo n.º 22
0
 internal static IsFalse IsFalse(UnaryExpression expression)
 {
     return new IsFalse()
     {
         Operand = Serialize(expression.Operand),
         Method = expression.Method.Null(m => MethodRef.Serialize(m)),
     }.Apply(n => n.Type = TypeRef.Serialize(expression.Type));
 }
Exemplo n.º 23
0
 internal static TypeAs TypeAs(UnaryExpression expression)
 {
     return new TypeAs()
     {
         Operand = Serialize(expression.Operand),
         Type = TypeRef.Serialize(expression.Type),
     };
 }
Exemplo n.º 24
0
 internal static NegateChecked NegateChecked(UnaryExpression expression)
 {
     return new NegateChecked()
     {
         Operand = Serialize(expression.Operand),
         Method = expression.Method.Null(m => MethodRef.Serialize(m)),
     }.Apply(n => n.Type = TypeRef.Serialize(expression.Type));
 }
Exemplo n.º 25
0
 public static XmlAryExpression From(UnaryExpression uex)
 {
     return new XmlAryExpression
     {
         NodeType = uex.NodeType,
         Method = XmlMetadataInfo.FromMetadata(uex.Method),
         Operands = XmlExpression.FromMany(new Expression[]{uex.Operand})
     };
 }
Exemplo n.º 26
0
            protected override Expression VisitUnary(UnaryExpression node)
            {
                if (node.NodeType == ExpressionType.Throw && node.Operand == null)
                {
                    return _replacement;
                }

                return base.VisitUnary(node);
            }
 public static UnaryExpressionFingerprint Create(UnaryExpression expression, ParserContext parserContext)
 {
     ExpressionFingerprint fingerprint = ExpressionFingerprint.Create(expression.Operand, parserContext);
     if ((fingerprint == null) && (expression.Operand != null))
     {
         return null;
     }
     return new UnaryExpressionFingerprint(expression) { Operand = fingerprint };
 }
Exemplo n.º 28
0
 internal static Rethrow Rethrow(UnaryExpression expression)
 {
     return new Rethrow()
     {
         Operand = Serialize(expression.Operand),
         Method = expression.Method.Null(m => MethodRef.Serialize(m)),
         Type = expression.Type.Null(t => TypeRef.Serialize(t)),
     }.If(n => n.Type == null, n => n.TypeHint = TypeRef.Serialize(expression.Type));
 }
        protected override Expression VisitUnaryExpression(UnaryExpression expression)
        {
            if (expression.NodeType == ExpressionType.Convert)
            {
                return base.VisitExpression(expression.Operand);
            }

            return base.VisitUnaryExpression(expression);
        }
        public static string JsonLocator(Type rootType, UnaryExpression expression)
        {
            if (expression.NodeType == ExpressionType.Convert)
            {
                return JsonLocator(rootType, expression.Operand);
            }

            throw new NotSupportedException();
        }
Exemplo n.º 31
0
        private string GetCode(UnaryExpression e)
        {
            if (e.NodeType == ExpressionType.Convert)
            {
                return $"({e.Type}) {e.Operand}";
            }

            return e.ToString();
        }
Exemplo n.º 32
0
 internal static Convert Convert(UnaryExpression expression)
 {
     return new Convert()
     {
         Operand = Serialize(expression.Operand),
         Type = TypeRef.Serialize(expression.Type),
         Method = expression.Method.Null(m => MethodRef.Serialize(m)),
     };
 }
		protected override Expression VisitUnary(UnaryExpression node)
		{
			if (node.NodeType == ExpressionType.Convert && node.Type.IsValueType && !node.Operand.Type.IsValueType)
			{
				return ProtectFromNull(node, node.Operand);
			}

			return base.VisitUnary(node);
		}
Exemplo n.º 34
0
 public static string GetExpressionText(System.Linq.Expressions.LambdaExpression expression)
 {
     if (expression.Body != null && expression.Body.NodeType == System.Linq.Expressions.ExpressionType.Convert)
     {
         System.Linq.Expressions.UnaryExpression exp = expression.Body as System.Linq.Expressions.UnaryExpression;
         expression = System.Linq.Expressions.Expression.Lambda(exp.Operand, expression.Parameters.ToArray <System.Linq.Expressions.ParameterExpression>());
     }
     return(ExpressionHelper.GetExpressionText(expression));
 }
Exemplo n.º 35
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);
        }
Exemplo n.º 36
0
        static string PropertyNameFromUnaryExpr(Exprs.UnaryExpression expr)
        {
            if (expr.NodeType == Exprs.ExpressionType.ArrayLength)
            {
                return("Length");
            }

            var mem_expr = expr.Operand as Exprs.MemberExpression;

            return(PropertyNameFromMemberExpr(mem_expr));
        }
Exemplo n.º 37
0
        static Reflect.MemberInfo MemberFromExprUnaryExpr(Exprs.UnaryExpression expr)
        {
            if (expr.NodeType == Exprs.ExpressionType.ArrayLength)
            {
                throw new NotSupportedException();
            }

            var mem_expr = expr.Operand as Exprs.MemberExpression;

            return(MemberFromExprMemberExpr(mem_expr));
        }
Exemplo n.º 38
0
        public static PropertyInfo GetPropertyName <T>(System.Linq.Expressions.Expression <Func <T, object> > property)
        {
            System.Linq.Expressions.LambdaExpression lambda = (System.Linq.Expressions.LambdaExpression)property;
            System.Linq.Expressions.MemberExpression memberExpression;

            if (lambda.Body is System.Linq.Expressions.UnaryExpression)
            {
                System.Linq.Expressions.UnaryExpression unaryExpression = (System.Linq.Expressions.UnaryExpression)(lambda.Body);
                memberExpression = (System.Linq.Expressions.MemberExpression)(unaryExpression.Operand);
            }
            else
            {
                memberExpression = (System.Linq.Expressions.MemberExpression)(lambda.Body);
            }

            return((PropertyInfo)memberExpression.Member);
        }
Exemplo n.º 39
0
        public static string GetPropertyName <TModel, TProperty>(System.Linq.Expressions.Expression <Func <TModel, TProperty> > property)
        {
            System.Linq.Expressions.LambdaExpression lambda = (System.Linq.Expressions.LambdaExpression)property;
            System.Linq.Expressions.MemberExpression memberExpression;

            if (lambda.Body is System.Linq.Expressions.UnaryExpression)
            {
                System.Linq.Expressions.UnaryExpression unaryExpression = (System.Linq.Expressions.UnaryExpression)(lambda.Body);
                memberExpression = (System.Linq.Expressions.MemberExpression)(unaryExpression.Operand);
            }
            else
            {
                memberExpression = (System.Linq.Expressions.MemberExpression)(lambda.Body);
            }
            var xx = (PropertyInfo)memberExpression.Member;

            return(((PropertyInfo)memberExpression.Member).Name);
        }
Exemplo n.º 40
0
        public static string GetDisplayName <TModel, TResult>(System.Linq.Expressions.Expression <Func <TModel, TResult> > property)
        {
            System.Linq.Expressions.LambdaExpression lambda = (System.Linq.Expressions.LambdaExpression)property;
            System.Linq.Expressions.MemberExpression memberExpression;

            if (lambda.Body is System.Linq.Expressions.UnaryExpression)
            {
                System.Linq.Expressions.UnaryExpression unaryExpression = (System.Linq.Expressions.UnaryExpression)(lambda.Body);
                memberExpression = (System.Linq.Expressions.MemberExpression)(unaryExpression.Operand);
            }
            else
            {
                memberExpression = (System.Linq.Expressions.MemberExpression)(lambda.Body);
            }
            var dispnameattr = memberExpression.Member.CustomAttributes.SingleOrDefault(at => at.AttributeType == typeof(DisplayNameAttribute));

            if (dispnameattr != null && dispnameattr.ConstructorArguments.Count > 0)
            {
                return(dispnameattr.ConstructorArguments[0].Value.ToString());
            }
            return(((PropertyInfo)memberExpression.Member).Name);
        }
        protected internal override Expression VisitUnary(UnaryExpression node)
        {
            switch (node.NodeType)
            {
            case ExpressionType.TypeAs:
                Out("(");
                break;

            case ExpressionType.Not:
                Out("Not(");
                break;

            case ExpressionType.Negate:
            case ExpressionType.NegateChecked:
                Out("-");
                break;

            case ExpressionType.UnaryPlus:
                Out("+");
                break;

            case ExpressionType.Quote:
                break;

            case ExpressionType.Throw:
                Out("throw(");
                break;

            case ExpressionType.Increment:
                Out("Increment(");
                break;

            case ExpressionType.Decrement:
                Out("Decrement(");
                break;

            case ExpressionType.PreIncrementAssign:
                Out("++");
                break;

            case ExpressionType.PreDecrementAssign:
                Out("--");
                break;

            case ExpressionType.OnesComplement:
                Out("~(");
                break;

            default:
                Out(node.NodeType.ToString());
                Out("(");
                break;
            }

            Visit(node.Operand);

            switch (node.NodeType)
            {
            case ExpressionType.Negate:
            case ExpressionType.NegateChecked:
            case ExpressionType.UnaryPlus:
            case ExpressionType.PreDecrementAssign:
            case ExpressionType.PreIncrementAssign:
            case ExpressionType.Quote:
                break;

            case ExpressionType.TypeAs:
                Out(" As ");
                Out(node.Type.Name);
                Out(")");
                break;

            case ExpressionType.PostIncrementAssign:
                Out("++");
                break;

            case ExpressionType.PostDecrementAssign:
                Out("--");
                break;

            default:
                Out(")");
                break;
            }
            return(node);
        }
Exemplo n.º 42
0
        protected Predicate <object> GenerateFilterPredicate(string propertyName, string filterValue, Type objType, Type propType, FilterOperationItem filterItem)
        {
            if (filterItem == null)
            {
                return(null);
            }
            if (propertyName == null)
            {
                throw new ArgumentNullException(nameof(propertyName));
            }
            if (filterValue == null)
            {
                throw new ArgumentNullException(nameof(filterValue));
            }
            if (objType == null)
            {
                throw new ArgumentNullException(nameof(objType));
            }

            ParameterExpression objParam = linq.Expression.Parameter(typeof(object), "x");

            linq.UnaryExpression param = objType.IsByRef ?
                                         linq.Expression.TypeAs(objParam, objType) :
                                         linq.Expression.Convert(objParam, objType);

            linq.Expression    prop = ExpressionProperty(propertyName, param);
            ConstantExpression val  = linq.Expression.Constant(filterValue);

            switch (filterItem.FilterOption)
            {
            case Enums.FilterOperation.Contains:
                return(ExpressionHelper.GenerateGeneric(prop, val, propType, objParam, "Contains"));

            case Enums.FilterOperation.EndsWith:
                return(ExpressionHelper.GenerateGeneric(prop, val, propType, objParam, "EndsWith"));

            case Enums.FilterOperation.StartsWith:
                return(ExpressionHelper.GenerateGeneric(prop, val, propType, objParam, "StartsWith"));

            case Enums.FilterOperation.Equals:
                return(ExpressionHelper.GenerateEquals(prop, filterValue, propType, objParam));

            case Enums.FilterOperation.NotEquals:
                return(ExpressionHelper.GenerateNotEquals(prop, filterValue, propType, objParam));

            case Enums.FilterOperation.GreaterThanEqual:
                return(ExpressionHelper.GenerateGreaterThanEqual(prop, filterValue, propType, objParam));

            case Enums.FilterOperation.LessThanEqual:
                return(ExpressionHelper.GenerateLessThanEqual(prop, filterValue, propType, objParam));

            case Enums.FilterOperation.GreaterThan:
                return(ExpressionHelper.GenerateGreaterThan(prop, filterValue, propType, objParam));

            case Enums.FilterOperation.LessThan:
                return(ExpressionHelper.GenerateLessThan(prop, filterValue, propType, objParam));

            default:
                throw new ArgumentException("Could not decode Search Mode.  Did you add a new value to the enum, or send in Unknown?");
            }
        }
Exemplo n.º 43
0
 private Expression Convert(LinqExp.UnaryExpression linqUnary, Func <Expression, Type, Expression> factory)
 {
     return(factory.Invoke(ConvertExp(linqUnary.Operand), linqUnary.Type));
 }
Exemplo n.º 44
0
        protected internal override Expression VisitUnary(UnaryExpression node)
        {
            switch (node.NodeType)
            {
            case ExpressionType.Convert:
                Out("(" + node.Type.ToString() + ")");
                break;

            case ExpressionType.ConvertChecked:
                Out("#(" + node.Type.ToString() + ")");
                break;

            case ExpressionType.TypeAs:
                break;

            case ExpressionType.Not:
                Out(node.Type == typeof(bool) ? "!" : "~");
                break;

            case ExpressionType.OnesComplement:
                Out("~");
                break;

            case ExpressionType.Negate:
                Out("-");
                break;

            case ExpressionType.NegateChecked:
                Out("#-");
                break;

            case ExpressionType.UnaryPlus:
                Out("+");
                break;

            case ExpressionType.ArrayLength:
                break;

            case ExpressionType.Quote:
                Out("'");
                break;

            case ExpressionType.Throw:
                if (node.Operand == null)
                {
                    Out(".Rethrow");
                }
                else
                {
                    Out(".Throw", Flow.Space);
                }
                break;

            case ExpressionType.IsFalse:
                Out(".IsFalse");
                break;

            case ExpressionType.IsTrue:
                Out(".IsTrue");
                break;

            case ExpressionType.Decrement:
                Out(".Decrement");
                break;

            case ExpressionType.Increment:
                Out(".Increment");
                break;

            case ExpressionType.PreDecrementAssign:
                Out("--");
                break;

            case ExpressionType.PreIncrementAssign:
                Out("++");
                break;

            case ExpressionType.Unbox:
                Out(".Unbox");
                break;
            }

            ParenthesizedVisit(node, node.Operand);

            switch (node.NodeType)
            {
            case ExpressionType.TypeAs:
                Out(Flow.Space, ".As", Flow.Space | Flow.Break);
                Out(node.Type.ToString());
                break;

            case ExpressionType.ArrayLength:
                Out(".Length");
                break;

            case ExpressionType.PostDecrementAssign:
                Out("--");
                break;

            case ExpressionType.PostIncrementAssign:
                Out("++");
                break;
            }
            return(node);
        }
Exemplo n.º 45
0
 /// <summary>
 /// Visits the children of the <see cref="UnaryExpression"/>.
 /// </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 VisitUnary(UnaryExpression node)
 {
     return(ValidateUnary(node, node.Update(Visit(node.Operand))));
 }
Exemplo n.º 46
0
        protected internal override Expression VisitUnary(UnaryExpression node)
        {
            switch (node.NodeType)
            {
            case ExpressionType.Negate:
            case ExpressionType.NegateChecked:       Out('-');               break;

            case ExpressionType.Not:                 Out("Not(");            break;

            case ExpressionType.IsFalse:             Out("IsFalse(");        break;

            case ExpressionType.IsTrue:              Out("IsTrue(");         break;

            case ExpressionType.OnesComplement:      Out("~(");              break;

            case ExpressionType.ArrayLength:         Out("ArrayLength(");    break;

            case ExpressionType.Convert:             Out("Convert(");        break;

            case ExpressionType.ConvertChecked:      Out("ConvertChecked("); break;

            case ExpressionType.Throw:               Out("throw(");          break;

            case ExpressionType.TypeAs:              Out('(');               break;

            case ExpressionType.UnaryPlus:           Out('+');               break;

            case ExpressionType.Unbox:               Out("Unbox(");          break;

            case ExpressionType.Increment:           Out("Increment(");      break;

            case ExpressionType.Decrement:           Out("Decrement(");      break;

            case ExpressionType.PreIncrementAssign:  Out("++");              break;

            case ExpressionType.PreDecrementAssign:  Out("--");              break;

            case ExpressionType.Quote:
            case ExpressionType.PostIncrementAssign:
            case ExpressionType.PostDecrementAssign:
                break;

            default:
                throw new InvalidOperationException();
            }

            Visit(node.Operand);

            switch (node.NodeType)
            {
            case ExpressionType.Negate:
            case ExpressionType.NegateChecked:
            case ExpressionType.UnaryPlus:
            case ExpressionType.PreDecrementAssign:
            case ExpressionType.PreIncrementAssign:
            case ExpressionType.Quote:
                break;

            case ExpressionType.TypeAs:              Out(" As ");
                Out(node.Type.Name);
                Out(')');               break;

            case ExpressionType.Convert:
            case ExpressionType.ConvertChecked:      Out(", ");
                Out(node.Type.Name);
                Out(')');               break;                                          // These were changed in CoreFx to add the type name

            case ExpressionType.PostIncrementAssign: Out("++");              break;

            case ExpressionType.PostDecrementAssign: Out("--");              break;

            default:                                 Out(')');               break;
            }
            return(node);
        }