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

ListBind() public static method

Creates a MemberListBinding based on a specified property accessor method.
/// is null. -or-One or more elements of are null. /// does not represent a property accessor method.-or-The of the property that the method represented by accesses does not implement .
public static ListBind ( MethodInfo propertyAccessor, IEnumerable initializers ) : MemberListBinding
propertyAccessor System.Reflection.MethodInfo A that represents a property accessor method.
initializers IEnumerable An that contains objects to use to populate the collection.
return MemberListBinding
        public static MemberListBinding ListBind(MethodInfo propertyAccessor, IEnumerable<ElementInit> initializers)
        {
            ContractUtils.RequiresNotNull(propertyAccessor, nameof(propertyAccessor));
            ContractUtils.RequiresNotNull(initializers, nameof(initializers));
            return ListBind(GetProperty(propertyAccessor, nameof(propertyAccessor)), initializers);
        }

Same methods

Expression::ListBind ( MemberInfo member ) : MemberListBinding
Expression::ListBind ( MemberInfo member, IEnumerable initializers ) : MemberListBinding
Expression::ListBind ( MethodInfo propertyAccessor ) : 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