System.Linq.Expressions.Expression.ListBind C# (CSharp) Méthode

ListBind() public static méthode

Creates a MemberListBinding where the member is a field or property.
/// is null. -or-One or more elements of is null. /// does not represent a field or property.-or-The or of the field or property that represents does not implement .
public static ListBind ( MemberInfo member, IEnumerable initializers ) : MemberListBinding
member System.Reflection.MemberInfo A that represents a field or property to set the property equal to.
initializers IEnumerable An that contains objects to use to populate the collection.
Résultat MemberListBinding
        public static MemberListBinding ListBind(MemberInfo member, IEnumerable<ElementInit> initializers)
        {
            ContractUtils.RequiresNotNull(member, nameof(member));
            ContractUtils.RequiresNotNull(initializers, nameof(initializers));
            Type memberType;
            ValidateGettableFieldOrPropertyMember(member, out memberType);
            ReadOnlyCollection<ElementInit> initList = initializers.ToReadOnly();
            ValidateListInitArgs(memberType, initList, nameof(member));
            return new MemberListBinding(member, initList);
        }

Same methods

Expression::ListBind ( MemberInfo member ) : MemberListBinding
Expression::ListBind ( MethodInfo propertyAccessor ) : MemberListBinding
Expression::ListBind ( MethodInfo propertyAccessor, IEnumerable initializers ) : MemberListBinding

Usage Example

        public void MemberInit_list_bind()
        {
            var expression =
                LinqExpression.MemberInit(
                    LinqExpression.New(
                        typeof(SampleClass)),
                    LinqExpression.ListBind(
                        typeof(SampleClass).GetProperty(nameof(SampleClass.ListProperty)),
                        LinqExpression.ElementInit(
                            typeof(List <long>).GetMethod("Add"),
                            LinqExpression.Constant(0L))));

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