Expression.ListInit Method (NewExpression, MethodInfo, Expression())
Creates a ListInitExpression that uses a specified method to add elements to a collection.
Assembly: System.Core (in System.Core.dll)
Public Shared Function ListInit ( newExpression As NewExpression, addMethod As MethodInfo, ParamArray initializers As Expression() ) As ListInitExpression
- Type: System.Linq.Expressions.NewExpression
A MethodInfo that represents an instance method that takes one argument, that adds an element to a collection.
newExpression or initializers is null.
One or more elements of initializers are null.
newExpression.Type does not implement IEnumerable.
addMethod is not null and it does not represent an instance method named "Add" (case insensitive) that takes exactly one argument.
addMethod is not null and the type represented by the Type property of one or more elements of initializers is not assignable to the argument type of the method that addMethod represents.
addMethod is null and no instance method named "Add" that takes one type-compatible argument exists on newExpression.Type or its base type.
If addMethod is null, newExpression.Type or its base type must declare a single method named "Add" (case insensitive) that takes exactly one argument. If addMethod is not null, it must represent an instance method named "Add" (case insensitive) that has exactly one parameter. The type represented by the Type property of each element of initializers must be assignable to the argument type of the add method.
The Initializers property of the returned ListInitExpressioncontains one element of type ElementInit for each element of initializers. The Arguments property of each element of Initializers is a singleton collection that contains the corresponding element of initializers. The AddMethod property of each element of Initializers is equal to addMethod.
Available since 8
Available since 3.5
Portable Class Library
Supported in: portable .NET platforms
Available since 2.0
Windows Phone Silverlight
Available since 7.0
Available since 8.1