/// <summary>
        /// Initializes a new instance of the <see cref="MemberInitExpressionRepresentation"/> class.
        /// </summary>
        /// <param name="type">The type.</param>
        /// <param name="newExpressionRepresentation">The new expression.</param>
        /// <param name="bindings">The bindings.</param>
        public MemberInitExpressionRepresentation(
            TypeRepresentation type,
            NewExpressionRepresentation newExpressionRepresentation,
            IReadOnlyCollection <MemberBindingRepresentationBase> bindings)
            : base(type, ExpressionType.MemberInit)
        {
            if (newExpressionRepresentation == null)
            {
                throw new ArgumentNullException(nameof(newExpressionRepresentation));
            }

            if (bindings == null)
            {
                throw new ArgumentNullException(nameof(bindings));
            }

            if (!bindings.Any())
            {
                throw new ArgumentException(Invariant($"'{nameof(bindings)}' is an empty enumerable"));
            }

            if (bindings.Any(_ => _ == null))
            {
                throw new ArgumentException(Invariant($"'{nameof(bindings)}' contains at least one null element"));
            }

            this.NewExpressionRepresentation = newExpressionRepresentation;
            this.Bindings = bindings;
        }
Example #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ConditionalExpressionRepresentation"/> class.
        /// </summary>
        /// <param name="type">The type of expression.</param>
        /// <param name="nodeType">Type of the node.</param>
        /// <param name="test">The test expression.</param>
        /// <param name="ifTrue">If true expression.</param>
        /// <param name="ifFalse">If false expression.</param>
        #pragma warning disable SA1305 // Field names should not use Hungarian notation
        public ConditionalExpressionRepresentation(
            TypeRepresentation type,
            ExpressionType nodeType,
            ExpressionRepresentationBase test,
            ExpressionRepresentationBase ifTrue,
            ExpressionRepresentationBase ifFalse)
            : base(type, nodeType)
        {
            if (test == null)
            {
                throw new ArgumentNullException(nameof(test));
            }

            if (ifTrue == null)
            {
                throw new ArgumentNullException(nameof(ifTrue));
            }

            if (ifFalse == null)
            {
                throw new ArgumentNullException(nameof(ifFalse));
            }

            this.Test    = test;
            this.IfTrue  = ifTrue;
            this.IfFalse = ifFalse;
        }
Example #3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ListInitExpressionRepresentation"/> class.
        /// </summary>
        /// <param name="type">The type of expression.</param>
        /// <param name="newExpressionRepresentation">The new expression.</param>
        /// <param name="initializers">The initializers.</param>
        public ListInitExpressionRepresentation(
            TypeRepresentation type,
            NewExpressionRepresentation newExpressionRepresentation,
            IReadOnlyList <ElementInitRepresentation> initializers)
            : base(type, ExpressionType.ListInit)
        {
            if (newExpressionRepresentation == null)
            {
                throw new ArgumentNullException(nameof(newExpressionRepresentation));
            }

            if (initializers == null)
            {
                throw new ArgumentNullException(nameof(initializers));
            }

            if (!initializers.Any())
            {
                throw new ArgumentException(Invariant($"'{nameof(initializers)}' is an empty enumerable"));
            }

            if (initializers.Any(_ => _ == null))
            {
                throw new ArgumentException(Invariant($"'{nameof(initializers)}' contains at least one null element"));
            }

            this.NewExpressionRepresentation = newExpressionRepresentation;
            this.Initializers = initializers;
        }
Example #4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="InvocationExpressionRepresentation"/> class.
        /// </summary>
        /// <param name="type">The type of expression.</param>
        /// <param name="expressionRepresentation">The expression to invoke.</param>
        /// <param name="arguments">The arguments to invoke with.</param>
        public InvocationExpressionRepresentation(
            TypeRepresentation type,
            ExpressionRepresentationBase expressionRepresentation,
            IReadOnlyList <ExpressionRepresentationBase> arguments)
            : base(type, ExpressionType.Invoke)
        {
            if (expressionRepresentation == null)
            {
                throw new ArgumentNullException(nameof(expressionRepresentation));
            }

            if (arguments == null)
            {
                throw new ArgumentNullException(nameof(arguments));
            }

            if (!arguments.Any())
            {
                throw new ArgumentException(Invariant($"'{nameof(arguments)}' is an empty enumerable"));
            }

            if (arguments.Any(_ => _ == null))
            {
                throw new ArgumentException(Invariant($"'{nameof(arguments)}' contains at least one null element"));
            }

            this.ExpressionRepresentation = expressionRepresentation;
            this.Arguments = arguments;
        }
Example #5
0
        /// <summary>
        /// Initializes a new instance of the <see cref="NewExpressionRepresentation"/> class.
        /// </summary>
        /// <param name="type">The type.</param>
        /// <param name="constructorInfo">The constructor info.</param>
        /// <param name="arguments">The arguments.</param>
        public NewExpressionRepresentation(
            TypeRepresentation type,
            ConstructorInfoRepresentation constructorInfo,
            IReadOnlyList <ExpressionRepresentationBase> arguments)
            : base(type, ExpressionType.New)
        {
            if (constructorInfo == null)
            {
                throw new ArgumentNullException(nameof(constructorInfo));
            }

            if (arguments == null)
            {
                throw new ArgumentNullException(nameof(arguments));
            }

            if (!arguments.Any())
            {
                throw new ArgumentException(Invariant($"'{nameof(arguments)}' is an empty enumerable"));
            }

            if (arguments.Any(_ => _ == null))
            {
                throw new ArgumentException(Invariant($"'{nameof(arguments)}' contains at least one null element"));
            }

            this.ConstructorInfo = constructorInfo;
            this.Arguments       = arguments;
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="ElementInitRepresentation"/> class.
        /// </summary>
        /// <param name="type">Type with method.</param>
        /// <param name="addMethod">The add method.</param>
        /// <param name="arguments">The arguments.</param>
        public ElementInitRepresentation(
            TypeRepresentation type,
            MethodInfoRepresentation addMethod,
            IReadOnlyList <ExpressionRepresentationBase> arguments)
        {
            if (type == null)
            {
                throw new ArgumentNullException(nameof(type));
            }

            if (addMethod == null)
            {
                throw new ArgumentNullException(nameof(addMethod));
            }

            if (arguments == null)
            {
                throw new ArgumentNullException(nameof(arguments));
            }

            if (!arguments.Any())
            {
                throw new ArgumentException(Invariant($"'{nameof(arguments)}' is an empty enumerable"));
            }

            if (arguments.Any(_ => _ == null))
            {
                throw new ArgumentException(Invariant($"'{nameof(arguments)}' contains at least one null element"));
            }

            this.Type      = type;
            this.AddMethod = addMethod;
            this.Arguments = arguments;
        }
Example #7
0
        /// <summary>
        /// Initializes a new instance of the <see cref="LambdaExpressionRepresentation"/> class.
        /// </summary>
        /// <param name="type">The type of expression.</param>
        /// <param name="body">The body.</param>
        /// <param name="parameters">The parameters.</param>
        public LambdaExpressionRepresentation(
            TypeRepresentation type,
            ExpressionRepresentationBase body,
            IReadOnlyList <ParameterExpressionRepresentation> parameters)
            : base(type, ExpressionType.Lambda)
        {
            if (body == null)
            {
                throw new ArgumentNullException(nameof(body));
            }

            if (parameters == null)
            {
                throw new ArgumentNullException(nameof(parameters));
            }

            if (!parameters.Any())
            {
                throw new ArgumentException(Invariant($"'{nameof(parameters)}' is an empty enumerable"));
            }

            if (parameters.Any(_ => _ == null))
            {
                throw new ArgumentException(Invariant($"'{nameof(parameters)}' contains at least one null element"));
            }

            this.Body       = body;
            this.Parameters = parameters;
        }
        public MemberInfoRepresentation DeepCloneWithType(TypeRepresentation type)
        {
            var result = new MemberInfoRepresentation(
                type,
                this.MemberHash?.DeepClone());

            return(result);
        }
        public override ExpressionRepresentationBase DeepCloneWithType(TypeRepresentation type)
        {
            var result = new ParameterExpressionRepresentation(
                type,
                this.Name?.DeepClone());

            return(result);
        }
        public override ExpressionRepresentationBase DeepCloneWithType(TypeRepresentation type)
        {
            var result = new TypeBinaryExpressionRepresentation(
                type,
                this.Expression?.DeepClone());

            return(result);
        }
        public ConstructorInfoRepresentation DeepCloneWithType(TypeRepresentation type)
        {
            var result = new ConstructorInfoRepresentation(
                type,
                this.ConstructorHash?.DeepClone());

            return(result);
        }
 /// <summary>Initializes a new instance of the <see cref="ConstantExpressionRepresentation{T}"/> class.</summary>
 /// <param name="type">The type of expression.</param>
 /// <param name="nodeType">The node type.</param>
 /// <param name="value">The value.</param>
 public ConstantExpressionRepresentation(
     TypeRepresentation type,
     ExpressionType nodeType,
     T value)
     : base(type, nodeType)
 {
     this.Value = value;
 }
        public override ExpressionRepresentationBase DeepCloneWithType(TypeRepresentation type)
        {
            var result = new NewArrayExpressionRepresentation(
                type,
                this.NodeType.DeepClone(),
                this.Expressions?.DeepClone());

            return(result);
        }
Example #14
0
        public MethodInfoRepresentation DeepCloneWithType(TypeRepresentation type)
        {
            var result = new MethodInfoRepresentation(
                type,
                this.MethodHash?.DeepClone(),
                this.GenericArguments?.DeepClone());

            return(result);
        }
        public override ExpressionRepresentationBase DeepCloneWithType(TypeRepresentation type)
        {
            var result = new InvocationExpressionRepresentation(
                type,
                this.ExpressionRepresentation?.DeepClone(),
                this.Arguments?.DeepClone());

            return(result);
        }
Example #16
0
        public override ExpressionRepresentationBase DeepCloneWithType(TypeRepresentation type)
        {
            var result = new NewExpressionRepresentation(
                type,
                this.ConstructorInfo?.DeepClone(),
                this.Arguments?.DeepClone());

            return(result);
        }
        public override ExpressionRepresentationBase DeepCloneWithType(TypeRepresentation type)
        {
            var result = new LambdaExpressionRepresentation(
                type,
                this.Body?.DeepClone(),
                this.Parameters?.DeepClone());

            return(result);
        }
        public override ExpressionRepresentationBase DeepCloneWithType(TypeRepresentation type)
        {
            var result = new ConstantExpressionRepresentation <T>(
                type,
                this.NodeType.DeepClone(),
                this.Value == null ? default : this.Value.DeepClone());

            return(result);
        }
Example #19
0
        public ElementInitRepresentation DeepCloneWithType(TypeRepresentation type)
        {
            var result = new ElementInitRepresentation(
                type,
                this.AddMethod?.DeepClone(),
                this.Arguments?.DeepClone());

            return(result);
        }
Example #20
0
        public override ExpressionRepresentationBase DeepCloneWithType(TypeRepresentation type)
        {
            var result = new UnaryExpressionRepresentation(
                type,
                this.NodeType.DeepClone(),
                this.Operand?.DeepClone());

            return(result);
        }
Example #21
0
        public override ExpressionRepresentationBase DeepCloneWithType(TypeRepresentation type)
        {
            var result = new ListInitExpressionRepresentation(
                type,
                this.NewExpressionRepresentation?.DeepClone(),
                this.Initializers?.DeepClone());

            return(result);
        }
        public override MemberBindingRepresentationBase DeepCloneWithType(TypeRepresentation type)
        {
            var result = new MemberListBindingRepresentation(
                type,
                this.MemberInfo?.DeepClone(),
                this.Initializers?.DeepClone());

            return(result);
        }
Example #23
0
        public override MemberBindingRepresentationBase DeepCloneWithType(TypeRepresentation type)
        {
            var result = new MemberAssignmentRepresentation(
                type,
                this.MemberInfo?.DeepClone(),
                this.ExpressionRepresentation?.DeepClone());

            return(result);
        }
Example #24
0
        public override ExpressionRepresentationBase DeepCloneWithType(TypeRepresentation type)
        {
            var result = new MemberInitExpressionRepresentation(
                type,
                this.NewExpressionRepresentation?.DeepClone(),
                this.Bindings?.DeepClone());

            return(result);
        }
Example #25
0
        public override ExpressionRepresentationBase DeepCloneWithType(TypeRepresentation type)
        {
            var result = new MethodCallExpressionRepresentation(
                type,
                this.NodeType.DeepClone(),
                this.ParentObject?.DeepClone(),
                this.Method?.DeepClone(),
                this.Arguments?.DeepClone());

            return(result);
        }
Example #26
0
        public override ExpressionRepresentationBase DeepCloneWithType(TypeRepresentation type)
        {
            var result = new ConditionalExpressionRepresentation(
                type,
                this.NodeType.DeepClone(),
                this.Test?.DeepClone(),
                this.IfTrue?.DeepClone(),
                this.IfFalse?.DeepClone());

            return(result);
        }
        /// <summary>
        /// Determines whether this type is a generic type.
        /// </summary>
        /// <param name="typeRepresentation">The type representation.</param>
        /// <returns>
        /// true if the type is a generic type, otherwise false.
        /// </returns>
        public static bool IsGenericType(
            this TypeRepresentation typeRepresentation)
        {
            if (typeRepresentation == null)
            {
                throw new ArgumentNullException(nameof(typeRepresentation));
            }

            var result = typeRepresentation.GenericArguments != null;

            return(result);
        }
        /// <summary>
        /// Determines whether this type is a generic type definition.
        /// </summary>
        /// <param name="typeRepresentation">The type representation.</param>
        /// <returns>
        /// true if the type is a generic type definition, otherwise false.
        /// </returns>
        public static bool IsGenericTypeDefinition(
            this TypeRepresentation typeRepresentation)
        {
            if (typeRepresentation == null)
            {
                throw new ArgumentNullException(nameof(typeRepresentation));
            }

            var result = typeRepresentation.IsGenericType() && (!typeRepresentation.GenericArguments.Any());

            return(result);
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="TypeBinaryExpressionRepresentation"/> class.
        /// </summary>
        /// <param name="type">The type.</param>
        /// <param name="expression">The expression.</param>
        public TypeBinaryExpressionRepresentation(
            TypeRepresentation type,
            ExpressionRepresentationBase expression)
            : base(type, ExpressionType.TypeIs)
        {
            if (expression == null)
            {
                throw new ArgumentNullException(nameof(expression));
            }

            this.Expression = expression;
        }
Example #30
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ExpressionRepresentationBase"/> class.
        /// </summary>
        /// <param name="type">The type of expression.</param>
        /// <param name="nodeType">The node type.</param>
        protected ExpressionRepresentationBase(
            TypeRepresentation type,
            ExpressionType nodeType)
        {
            if (type == null)
            {
                throw new ArgumentNullException(nameof(type));
            }

            this.Type     = type;
            this.NodeType = nodeType;
        }