System.Linq.Expressions.Expression.ElementInit C# (CSharp) Method

ElementInit() public static method

Creates an Expressions.ElementInit expression that represents the initialization of a list.
public static ElementInit ( MethodInfo addMethod, IEnumerable arguments ) : ElementInit
addMethod System.Reflection.MethodInfo The for the list's Add method.
arguments IEnumerable An containing elements to initialize the list.
return ElementInit
        public static ElementInit ElementInit(MethodInfo addMethod, IEnumerable<Expression> arguments)
        {
            ContractUtils.RequiresNotNull(addMethod, nameof(addMethod));
            ContractUtils.RequiresNotNull(arguments, nameof(arguments));

            ReadOnlyCollection<Expression> argumentsRO = arguments.ToReadOnly();

            RequiresCanRead(argumentsRO, nameof(arguments));
            ValidateElementInitAddMethodInfo(addMethod, nameof(addMethod));
            ValidateArgumentTypes(addMethod, ExpressionType.Call, ref argumentsRO, nameof(addMethod));
            return new ElementInit(addMethod, argumentsRO);
        }

Same methods

Expression::ElementInit ( MethodInfo addMethod ) : ElementInit

Usage Example

コード例 #1
0
        public void ListInit()
        {
            var expression =
                LinqExpression.ListInit(
                    LinqExpression.New(
                        typeof(List <long>)),
                    LinqExpression.ElementInit(
                        typeof(List <long>).GetMethod("Add"),
                        LinqExpression.Constant(0L)));

            ShouldRoundrip(expression);
        }
All Usage Examples Of System.Linq.Expressions.Expression::ElementInit
Expression