예제 #1
0
 public SerializableConditionalExpression(ConditionalExpression expression, SerializableExpressionConverter converter)
     : base(expression)
 {
     IfFalse = converter.Convert(expression.IfFalse);
     IfTrue  = converter.Convert(expression.IfTrue);
     Test    = converter.Convert(expression.Test);
 }
        protected internal override void VisitMethodCall(SerializableMethodCallExpression node)
        {
            int start = 0;
            SerializableExpression ob = node.Object;

            if (node.Method.Item1.GetCustomAttributes(typeof(ExtensionAttribute), inherit: true).Any())
            {
                start = 1;
                ob    = node.Arguments[0];
            }

            if (ob != null)
            {
                Visit(ob);
                Out(".");
            }
            Out(node.Method.Item1.Name);
            Out("(");
            for (int i = start, n = node.Arguments.Count; i < n; i++)
            {
                if (i > start)
                {
                    Out(", ");
                }
                Visit(node.Arguments[i]);
            }
            Out(")");
        }
예제 #3
0
 public void Visit(SerializableExpression node)
 {
     if (node != null)
     {
         node.Accept(this);
     }
 }
예제 #4
0
 public SerializableIndexExpression(IndexExpression expression, SerializableExpressionConverter converter)
     : base(expression)
 {
     Arguments = converter.Convert(expression.Arguments);
     Indexer   = expression.Indexer;
     Object    = converter.Convert(expression.Object);
 }
 public SerializableLabelExpression(LabelExpression expression, SerializableExpressionConverter converter)
     : base(expression)
 {
     DefaultValue = converter.Convert(expression.DefaultValue);
     TargetName   = expression.Target.Name;
     TargetType   = expression.Target.Type;
 }
 public SerializableBlockExpression(BlockExpression expression, SerializableExpressionConverter converter)
     : base(expression)
 {
     Expressions = converter.Convert(expression.Expressions);
     Result      = converter.Convert(expression.Result);
     Variables   = converter.Convert <SerializableParameterExpression>(expression.Variables);
 }
 public SerializableMethodCallExpression(MethodCallExpression expression, SerializableExpressionConverter converter)
     : base(expression)
 {
     Arguments = converter.Convert(expression.Arguments);
     Method    = SerializableExpressionConverter.Convert(expression.Method);
     Object    = converter.Convert(expression.Object);
 }
 public SerializableLambdaExpression(LambdaExpression expression, SerializableExpressionConverter converter)
     : base(expression)
 {
     Body       = converter.Convert(expression.Body);
     Name       = expression.Name;
     Parameters = converter.Convert <SerializableParameterExpression>(expression.Parameters);
     TailCall   = expression.TailCall;
 }
예제 #9
0
 public SerializableGotoExpression(GotoExpression expression, SerializableExpressionConverter converter)
     : base(expression)
 {
     Kind       = expression.Kind;
     TargetName = expression.Target.Name;
     TargetType = expression.Target.Type;
     Value      = converter.Convert(expression.Value);
 }
        /// <summary>
        /// Output a given expression tree to a string.
        /// </summary>
        internal static string ExpressionToString(SerializableExpression node)
        {
            Debug.Assert(node != null);
            SerializableExpressionStringBuilder esb = new SerializableExpressionStringBuilder();

            esb.Visit(node);
            return(esb.ToString());
        }
예제 #11
0
 public SerializableSwitchExpression(SwitchExpression expression, SerializableExpressionConverter converter)
     : base(expression)
 {
     Cases       = expression.Cases.Select(c => Tuple.Create(converter.Convert(c.Body), converter.Convert(c.TestValues))).ToList();
     Comparison  = SerializableExpressionConverter.Convert(expression.Comparison);
     DefaultBody = converter.Convert(expression.DefaultBody);
     SwitchValue = converter.Convert(expression.SwitchValue);
 }
예제 #12
0
        public SerializableTypeBinaryExpression(TypeBinaryExpression expression, SerializableExpressionConverter converter)
            : base(expression)
        {
            Contract.Requires(expression != null);
            Contract.Requires(converter != null);

            Expr        = converter.TryConvert(expression.Expression);
            TypeOperand = expression.TypeOperand;
        }
        public SerializableUnaryExpression(UnaryExpression expression, SerializableExpressionConverter converter)
            : base(expression)
        {
            Contract.Requires(expression != null);
            Contract.Requires(converter != null);

            Method  = SerializableExpressionConverter.Convert(expression.Method);
            Operand = converter.TryConvert(expression.Operand);
        }
 public SerializableLoopExpression(LoopExpression expression, SerializableExpressionConverter converter)
     : base(expression)
 {
     Body              = converter.Convert(expression.Body);
     BreakLabelType    = expression.BreakLabel.Type;
     BreakLabelName    = expression.BreakLabel.Name;
     ContinueLabelType = expression.ContinueLabel.Type;
     ContinueLabelName = expression.ContinueLabel.Name;
 }
    public SerializableInvocationExpression(InvocationExpression expression, SerializableExpressionConverter converter)
      : base(expression)
    {
      Contract.Requires(expression != null);
      Contract.Requires(converter != null);

      Arguments = converter.TryConvert(expression.Arguments);
      Expr = converter.TryConvert(expression.Expression);
    }
예제 #16
0
 public SerializableBinaryExpression(BinaryExpression expression, SerializableExpressionConverter converter)
     : base(expression)
 {
     Conversion     = converter.Convert <SerializableLambdaExpression>(expression.Conversion);
     IsLiftedToNull = expression.IsLiftedToNull;
     Left           = converter.Convert(expression.Left);
     Method         = SerializableExpressionConverter.Convert(expression.Method);
     Right          = converter.Convert(expression.Right);
 }
예제 #17
0
        public SerializableMemberExpression(MemberExpression expression, SerializableExpressionConverter converter)
            : base(expression)
        {
            Contract.Requires(expression != null);
            Contract.Requires(converter != null);

            Expr   = converter.TryConvert(expression.Expression);
            Member = converter.Convert(expression.Member);
        }
        public SerializableMethodCallExpression(MethodCallExpression expression, SerializableExpressionConverter converter)
            : base(expression)
        {
            Contract.Requires(expression != null);
            Contract.Requires(converter != null);

            Arguments = converter.TryConvert(expression.Arguments);
            Method    = SerializableExpressionConverter.Convert(expression.Method);
            Object    = converter.TryConvert(expression.Object);
        }
        public SerializableBlockExpression(BlockExpression expression, SerializableExpressionConverter converter)
            : base(expression)
        {
            Contract.Requires(expression != null);
            Contract.Requires(converter != null);

            Expressions = converter.TryConvert(expression.Expressions);
            Result      = converter.TryConvert(expression.Result);
            Variables   = converter.TryConvert <SerializableParameterExpression>(expression.Variables);
        }
        public SerializableIndexExpression(IndexExpression expression, SerializableExpressionConverter converter)
            : base(expression)
        {
            Contract.Requires(expression != null);
            Contract.Requires(converter != null);

            Arguments = converter.TryConvert(expression.Arguments);
            Indexer   = expression.Indexer;
            Object    = converter.TryConvert(expression.Object);
        }
        public SerializableConditionalExpression(ConditionalExpression expression, SerializableExpressionConverter converter)
            : base(expression)
        {
            Contract.Requires(expression != null);
            Contract.Requires(converter != null);

            IfFalse = converter.TryConvert(expression.IfFalse);
            IfTrue  = converter.TryConvert(expression.IfTrue);
            Test    = converter.TryConvert(expression.Test);
        }
예제 #22
0
        public SerializableLabelExpression(LabelExpression expression, SerializableExpressionConverter converter)
            : base(expression)
        {
            Contract.Requires(expression != null);
            Contract.Requires(converter != null);

            DefaultValue = converter.TryConvert(expression.DefaultValue);
            TargetName   = expression.Target.Name;
            TargetType   = expression.Target.Type;
        }
        public SerializableGotoExpression(GotoExpression expression, SerializableExpressionConverter converter)
            : base(expression)
        {
            Contract.Requires(expression != null);
            Contract.Requires(converter != null);

            Kind       = expression.Kind;
            TargetName = expression.Target.Name;
            TargetType = expression.Target.Type;
            Value      = converter.TryConvert(expression.Value);
        }
예제 #24
0
        public SerializableLambdaExpression(LambdaExpression expression, SerializableExpressionConverter converter)
            : base(expression)
        {
            Contract.Requires(expression != null);
            Contract.Requires(converter != null);

            Body       = converter.TryConvert(expression.Body);
            Name       = expression.Name;
            Parameters = converter.TryConvert <SerializableParameterExpression>(expression.Parameters);
            TailCall   = expression.TailCall;
        }
        public SerializableLoopExpression(LoopExpression expression, SerializableExpressionConverter converter)
            : base(expression)
        {
            Contract.Requires(expression != null);
            Contract.Requires(converter != null);

            Body              = converter.TryConvert(expression.Body);
            BreakLabelType    = expression.BreakLabel.Type;
            BreakLabelName    = expression.BreakLabel.Name;
            ContinueLabelType = expression.ContinueLabel.Type;
            ContinueLabelName = expression.ContinueLabel.Name;
        }
예제 #26
0
 public SerializableTryExpression(TryExpression expression, SerializableExpressionConverter converter)
     : base(expression)
 {
     Body     = converter.Convert(expression.Body);
     Fault    = converter.Convert(expression.Fault);
     Finally  = converter.Convert(expression.Finally);
     Handlers = expression.Handlers
                .Select(h => Tuple.Create(
                            converter.Convert(h.Body),
                            converter.Convert(h.Filter),
                            h.Test,
                            converter.Convert <SerializableParameterExpression>(h.Variable)))
                .ToList();
 }
        // Prints ".instanceField" or "declaringType.staticField"
        private void OutMember(SerializableExpression instance, Tuple <MemberInfo, Type[]> member)
        {
            if (instance != null)
            {
                Visit(instance);
                Out("." + member.Item1.Name);
            }
            else
            {
                // For static members, include the type name
                Out(member.Item1.DeclaringType.Name + "." + member.Item1.Name);
            }

            // TODO: Include the parameters? (member.Item2)
        }
        protected internal override void VisitExtension(SerializableExpression node)
        {
            // Prefer an overridden ToString, if available.
            var toString = node.GetType().GetMethod("ToString", Type.EmptyTypes);

            if (toString.DeclaringType != typeof(SerializableExpression) && !toString.IsStatic)
            {
                Out(node.ToString());
                return;
            }

            Out("[");
            // For 3.5 subclasses, print the NodeType.
            // For Extension nodes, print the class name.
            if (node.NodeType == ExpressionType.Extension)
            {
                Out(node.GetType().FullName);
            }
            else
            {
                Out(node.NodeType.ToString());
            }
            Out("]");
        }
예제 #29
0
 protected internal abstract void VisitExtension(SerializableExpression node);
 public static Expression TryConvert(SerializableExpression expression)
 => expression.TryConvertBack();