public static Dictionary <string, object> Pack(MemberExpression expression)
        {
            if (expression == null)
            {
                throw new ArgumentNullException("expression");
            }


            if (expression.Expression != null)
            {
                var memberAccessExpression = new Dictionary <string, object>(3)
                {
                    { Constants.EXPRESSION_TYPE_ATTRIBUTE, Constants.EXPRESSION_TYPE_MEMBER_RESOLVE },
                    { Constants.NAME_ATTRIBUTE, expression.Member.Name },
                    { Constants.EXPRESSION_ATTRIBUTE, AnyPacker.Pack(expression.Expression) },
                };
                return(memberAccessExpression);
            }
            else
            {
                var memberAccessExpression = new Dictionary <string, object>(2)
                {
                    { Constants.EXPRESSION_TYPE_ATTRIBUTE, Constants.EXPRESSION_TYPE_MEMBER_RESOLVE },
                    { Constants.MEMBER_ATTRIBUTE, AnyPacker.Pack(expression.Member) }
                };
                return(memberAccessExpression);
            }
        }
예제 #2
0
        public static Dictionary <string, object> Pack(NewArrayExpression expression)
        {
            if (expression == null)
            {
                throw new ArgumentNullException("expression");
            }

            var arguments   = expression.Expressions.ToArray();
            var elementType = expression.Type.GetTypeInfo().GetElementType();

            // ReSharper disable once SwitchStatementMissingSomeCases
            switch (expression.NodeType)
            {
            case ExpressionType.NewArrayBounds:
                return(new Dictionary <string, object>(3)
                {
                    { Constants.EXPRESSION_TYPE_ATTRIBUTE, Constants.EXPRESSION_TYPE_NEW_ARRAY_BOUNDS },
                    { Constants.TYPE_ATTRIBUTE, AnyPacker.Pack(elementType) },
                    { Constants.ARGUMENTS_ATTRIBUTE, AnyPacker.Pack(arguments, names: null) },
                });

            case ExpressionType.NewArrayInit:
                return(new Dictionary <string, object>(3)
                {
                    { Constants.EXPRESSION_TYPE_ATTRIBUTE, Constants.EXPRESSION_TYPE_NEW_ARRAY_INIT },
                    { Constants.TYPE_ATTRIBUTE, AnyPacker.Pack(elementType) },
                    { Constants.ARGUMENTS_ATTRIBUTE, AnyPacker.Pack(arguments, names: null) },
                });

            default: throw new InvalidOperationException("Invalid expression type for this packer.");
            }
        }
예제 #3
0
        public static Dictionary <string, object> Pack(UnaryExpression expression)
        {
            if (expression == null)
            {
                throw new ArgumentNullException("expression");
            }

            return(new Dictionary <string, object>(2)
            {
                { Constants.EXPRESSION_TYPE_ATTRIBUTE, Constants.EXPRESSION_TYPE_QUOTE },
                { Constants.EXPRESSION_ATTRIBUTE, AnyPacker.Pack(expression.Operand) }
            });
        }
        public static Dictionary <string, object> Pack(MemberListBinding memberListBinding)
        {
            if (memberListBinding == null)
            {
                throw new ArgumentNullException("memberListBinding");
            }

            return(new Dictionary <string, object>(3)
            {
                { Constants.TYPE_ATTRIBUTE, "ListBinding" },
                { Constants.MEMBER_ATTRIBUTE, AnyPacker.Pack(memberListBinding.Member) },
                { Constants.INITIALIZERS_ATTRIBUTE, Pack(memberListBinding.Initializers) }
            });
        }
        public static Dictionary <string, object> Pack(MemberInitExpression expression)
        {
            if (expression == null)
            {
                throw new ArgumentNullException("expression");
            }

            return(new Dictionary <string, object>(3)
            {
                { Constants.EXPRESSION_TYPE_ATTRIBUTE, Constants.EXPRESSION_TYPE_MEMBER_INIT },
                { Constants.NEW_ATTRIBUTE, AnyPacker.Pack(expression.NewExpression) },
                { Constants.BINDINGS_ATTRIBUTE, Pack(expression.Bindings) },
            });
        }
        public static Dictionary <string, object> Pack(MemberAssignment memberAssignment)
        {
            if (memberAssignment == null)
            {
                throw new ArgumentNullException("memberAssignment");
            }

            return(new Dictionary <string, object>
            {
                { Constants.TYPE_ATTRIBUTE, "Assignment" },
                { Constants.MEMBER_ATTRIBUTE, AnyPacker.Pack(memberAssignment.Member) },
                { Constants.EXPRESSION_ATTRIBUTE, AnyPacker.Pack(memberAssignment.Expression) }
            });
        }
예제 #7
0
        public static Dictionary <string, object> Pack(ConstantExpression expression)
        {
            if (expression == null)
            {
                throw new ArgumentNullException("expression");
            }

            return(new Dictionary <string, object>(3)
            {
                { Constants.EXPRESSION_TYPE_ATTRIBUTE, Constants.EXPRESSION_TYPE_CONSTANT },
                { Constants.TYPE_ATTRIBUTE, AnyPacker.Pack(expression.Type) },
                { Constants.VALUE_ATTRIBUTE, expression.Value },
            });
        }
예제 #8
0
        public static Dictionary <string, object> Pack(ListInitExpression expression)
        {
            if (expression == null)
            {
                throw new ArgumentNullException("expression");
            }

            return(new Dictionary <string, object>(3)
            {
                { Constants.EXPRESSION_TYPE_ATTRIBUTE, Constants.EXPRESSION_TYPE_LIST_INIT },
                { Constants.NEW_ATTRIBUTE, AnyPacker.Pack(expression.NewExpression) },
                { Constants.INITIALIZERS_ATTRIBUTE, MemberInitPacker.Pack(expression.Initializers) },
            });
        }
예제 #9
0
        public static Dictionary <string, object> Pack(ParameterExpression expression)
        {
            if (expression == null)
            {
                throw new ArgumentNullException("expression");
            }

            return(new Dictionary <string, object>(3)
            {
                { Constants.EXPRESSION_TYPE_ATTRIBUTE, Constants.EXPRESSION_TYPE_PARAMETER },
                { Constants.TYPE_ATTRIBUTE, AnyPacker.Pack(expression.Type) },
                { Constants.NAME_ATTRIBUTE, expression.Name },
            });
        }
예제 #10
0
        public static Dictionary <string, object> Pack(TypeBinaryExpression expression)
        {
            if (expression == null)
            {
                throw new ArgumentNullException("expression");
            }

            return(new Dictionary <string, object>(3)
            {
                { Constants.EXPRESSION_TYPE_ATTRIBUTE, Constants.EXPRESSION_TYPE_TYPE_IS },
                { Constants.EXPRESSION_ATTRIBUTE, AnyPacker.Pack(expression.Expression) },
                { Constants.TYPE_ATTRIBUTE, AnyPacker.Pack(expression.TypeOperand) },
            });
        }
        public static Dictionary <string, object> Pack(MemberMemberBinding memberMemberBinding)
        {
            if (memberMemberBinding == null)
            {
                throw new ArgumentNullException("memberMemberBinding");
            }

            return(new Dictionary <string, object>(3)
            {
                { Constants.TYPE_ATTRIBUTE, "MemberBinding" },
                { Constants.MEMBER_ATTRIBUTE, AnyPacker.Pack(memberMemberBinding.Member) },
                { Constants.BINDINGS_ATTRIBUTE, Pack(memberMemberBinding.Bindings) }
            });
        }
        public static Dictionary <string, object> Pack(ElementInit elementInit)
        {
            if (elementInit == null)
            {
                throw new ArgumentNullException("elementInit");
            }

            var arguments = elementInit.Arguments.ToArray();

            return(new Dictionary <string, object>(2)
            {
                { Constants.METHOD_ATTRIBUTE, AnyPacker.Pack(elementInit.AddMethod) },
                { Constants.ARGUMENTS_ATTRIBUTE, AnyPacker.Pack(arguments, null) }
            });
        }
예제 #13
0
        public static Dictionary <string, object> Pack(ConditionalExpression expression)
        {
            if (expression == null)
            {
                throw new ArgumentNullException("expression");
            }

            return(new Dictionary <string, object>(4)
            {
                { Constants.EXPRESSION_TYPE_ATTRIBUTE, Constants.EXPRESSION_TYPE_CONDITION },
                { Constants.TEST_ATTRIBUTE, AnyPacker.Pack(expression.Test) },
                { Constants.IF_TRUE_ATTRIBUTE, AnyPacker.Pack(expression.IfTrue) },
                { Constants.IF_FALSE_ATTRIBUTE, AnyPacker.Pack(expression.IfFalse) },
            });
        }
예제 #14
0
        public static Dictionary <string, object> Pack(UnaryExpression expression)
        {
            if (expression == null)
            {
                throw new ArgumentNullException("expression");
            }

            return(new Dictionary <string, object>(3)
            {
                { Constants.EXPRESSION_TYPE_ATTRIBUTE, expression.NodeType == ExpressionType.Convert ?
                  Constants.EXPRESSION_TYPE_CONVERT :
                  Constants.EXPRESSION_TYPE_CONVERT_CHECKED },
                { Constants.EXPRESSION_ATTRIBUTE, AnyPacker.Pack(expression.Operand) },
                { Constants.TYPE_ATTRIBUTE, AnyPacker.Pack(expression.Type) },
            });
        }
예제 #15
0
        public static Dictionary <string, object> Pack(InvocationExpression expression)
        {
            if (expression == null)
            {
                throw new ArgumentNullException("expression");
            }

            var arguments = expression.Arguments.ToArray();

            return(new Dictionary <string, object>(3)
            {
                { Constants.EXPRESSION_TYPE_ATTRIBUTE, Constants.EXPRESSION_TYPE_INVOKE },
                { Constants.EXPRESSION_ATTRIBUTE, AnyPacker.Pack(expression.Expression) },
                { Constants.ARGUMENTS_ATTRIBUTE, AnyPacker.Pack(arguments, null) },
            });
        }
예제 #16
0
        public static Dictionary <string, object> Pack(NewExpression expression)
        {
            if (expression == null)
            {
                throw new ArgumentNullException("expression");
            }

            var arguments     = expression.Arguments.ToArray();
            var argumentNames = ArrayUtils.ConvertAll(expression.Constructor.GetParameters(), p => p.Name);

            return(new Dictionary <string, object>(3)
            {
                { Constants.EXPRESSION_TYPE_ATTRIBUTE, Constants.EXPRESSION_TYPE_NEW },
                { Constants.METHOD_ATTRIBUTE, AnyPacker.Pack(expression.Constructor) },
                { Constants.ARGUMENTS_ATTRIBUTE, AnyPacker.Pack(arguments, argumentNames) },
            });
        }
예제 #17
0
        public static Dictionary <string, object> Pack(UnaryExpression expression)
        {
            if (expression == null)
            {
                throw new ArgumentNullException("expression");
            }

            var expressionType = string.Empty;

            // ReSharper disable once SwitchStatementMissingSomeCases
            switch (expression.NodeType)
            {
            case ExpressionType.Not:
                expressionType = Constants.EXPRESSION_TYPE_NOT;
                break;

            case ExpressionType.NegateChecked:
                expressionType = Constants.EXPRESSION_TYPE_NEGATE_CHECKED;
                break;

            case ExpressionType.Negate:
                expressionType = Constants.EXPRESSION_TYPE_NEGATE;
                break;

            case ExpressionType.UnaryPlus:
                expressionType = Constants.EXPRESSION_TYPE_UNARY_PLUS;
                break;

            default: throw new InvalidOperationException("Invalid expression type for this packer.");
            }

            var node = new Dictionary <string, object>(3)
            {
                { Constants.EXPRESSION_TYPE_ATTRIBUTE, expressionType },
                { Constants.EXPRESSION_ATTRIBUTE, AnyPacker.Pack(expression.Operand) }
            };

            if (expression.Method != null)
            {
                node.Add(Constants.METHOD_ATTRIBUTE, AnyPacker.Pack(expression.Method));
            }
            return(node);
        }
예제 #18
0
        public static Dictionary <string, object> Pack(LambdaExpression expression)
        {
            if (expression == null)
            {
                throw new ArgumentNullException("expression");
            }

            var arguments = new Dictionary <string, object>(expression.Parameters.Count);

            for (var p = 0; p < expression.Parameters.Count; p++)
            {
                var key = Constants.GetIndexAsString(p);
                arguments[key] = AnyPacker.Pack(expression.Parameters[p]);
            }

            return(new Dictionary <string, object>(4)
            {
                { Constants.EXPRESSION_TYPE_ATTRIBUTE, Constants.EXPRESSION_TYPE_LAMBDA },
                { Constants.TYPE_ATTRIBUTE, AnyPacker.Pack(expression.Type) },
                { Constants.EXPRESSION_ATTRIBUTE, AnyPacker.Pack(expression.Body) },
                { Constants.ARGUMENTS_ATTRIBUTE, arguments }
            });
        }
예제 #19
0
        public static Dictionary <string, object> Pack(Expression expression)
        {
            if (expression == null)
            {
                throw new ArgumentNullException("expression");
            }

            var binaryExpression = expression as BinaryExpression;
            var methodCall       = expression as MethodCallExpression;
            var arguments        = default(Expression[]);
            var argumentNames    = default(string[]);
            var operand          = default(Expression);

            if (methodCall != null)
            {
                arguments     = methodCall.Arguments.ToArray();
                operand       = methodCall.Object;
                argumentNames = ArrayUtils.ConvertAll(methodCall.Method.GetParameters(), p => p.Name);
            }
            else if (binaryExpression != null)
            {
                arguments = new[] { binaryExpression.Right };
                operand   = binaryExpression.Left;
            }
            else
            {
                throw new InvalidOperationException("Invalid expression type for this packer.");
            }

            return(new Dictionary <string, object>(4)
            {
                { Constants.EXPRESSION_TYPE_ATTRIBUTE, Constants.EXPRESSION_TYPE_INDEX },
                { Constants.EXPRESSION_ATTRIBUTE, AnyPacker.Pack(operand) },
                { Constants.ARGUMENTS_ATTRIBUTE, AnyPacker.Pack(arguments, argumentNames) }
            });
        }
예제 #20
0
        public static Dictionary <string, object> Pack(BinaryExpression expression)
        {
            if (expression == null)
            {
                throw new ArgumentNullException("expression");
            }

            var expressionType = string.Empty;

            // ReSharper disable once SwitchStatementMissingSomeCases
            switch (expression.NodeType)
            {
            case ExpressionType.RightShift: expressionType = Constants.EXPRESSION_TYPE_RIGHT_SHIFT; break;

            case ExpressionType.Subtract: expressionType = Constants.EXPRESSION_TYPE_SUBTRACT; break;

            case ExpressionType.SubtractChecked: expressionType = Constants.EXPRESSION_TYPE_SUBTRACT_CHECKED; break;

            case ExpressionType.Power: expressionType = Constants.EXPRESSION_TYPE_POWER; break;

            case ExpressionType.NotEqual: expressionType = Constants.EXPRESSION_TYPE_NOT_EQUAL; break;

            case ExpressionType.Or: expressionType = Constants.EXPRESSION_TYPE_OR; break;

            case ExpressionType.OrElse: expressionType = Constants.EXPRESSION_TYPE_OR_ELSE; break;

            case ExpressionType.MultiplyChecked: expressionType = Constants.EXPRESSION_TYPE_MULTIPLY_CHECKED; break;

            case ExpressionType.Multiply: expressionType = Constants.EXPRESSION_TYPE_MULTIPLY; break;

            case ExpressionType.Modulo: expressionType = Constants.EXPRESSION_TYPE_MODULO; break;

            case ExpressionType.LessThan: expressionType = Constants.EXPRESSION_TYPE_LESS_THAN; break;

            case ExpressionType.LessThanOrEqual: expressionType = Constants.EXPRESSION_TYPE_LESS_THAN_OR_EQUAL; break;

            case ExpressionType.LeftShift: expressionType = Constants.EXPRESSION_TYPE_LEFT_SHIFT; break;

            case ExpressionType.GreaterThanOrEqual: expressionType = Constants.EXPRESSION_TYPE_GREATER_THAN_OR_EQUAL; break;

            case ExpressionType.GreaterThan: expressionType = Constants.EXPRESSION_TYPE_GREATER_THAN; break;

            case ExpressionType.ExclusiveOr: expressionType = Constants.EXPRESSION_TYPE_EXCLUSIVE_OR; break;

            case ExpressionType.Equal: expressionType = Constants.EXPRESSION_TYPE_EQUAL; break;

            case ExpressionType.Divide: expressionType = Constants.EXPRESSION_TYPE_DIVIDE; break;

            case ExpressionType.Coalesce: expressionType = Constants.EXPRESSION_TYPE_COALESCE; break;

            case ExpressionType.AndAlso: expressionType = Constants.EXPRESSION_TYPE_AND_ALSO; break;

            case ExpressionType.And: expressionType = Constants.EXPRESSION_TYPE_AND; break;

            case ExpressionType.AddChecked: expressionType = Constants.EXPRESSION_TYPE_ADD_CHECKED; break;

            case ExpressionType.Add: expressionType = Constants.EXPRESSION_TYPE_ADD; break;

            default: throw new InvalidOperationException("Invalid expression type for this packer.");
            }

            var node = new Dictionary <string, object>(4)
            {
                { Constants.EXPRESSION_TYPE_ATTRIBUTE, expressionType },
                { Constants.LEFT_ATTRIBUTE, AnyPacker.Pack(expression.Left) },
                { Constants.RIGHT_ATTRIBUTE, AnyPacker.Pack(expression.Right) }
            };

            if (expression.Method != null)
            {
                node.Add(Constants.METHOD_ATTRIBUTE, AnyPacker.Pack(expression.Method));
            }
            if (expression.Conversion != null)
            {
                node.Add(Constants.CONVERSION_ATTRIBUTE, AnyPacker.Pack(expression.Conversion));
            }
            return(node);
        }