This documentation is archived and is not being maintained.
MemberInitExpression Class
Visual Studio 2008
Represents calling a constructor and initializing one or more members of the new object.
Assembly: System.Core (in System.Core.dll)
Use the MemberInit factory methods to create a MemberInitExpression.
The value of the NodeType property of a MemberInitExpression is MemberInit.
The following example creates a MemberInitExpression that represents the initialization of two members of a new object.
Class Animal Public Species As String Public Age As Integer End Class Shared Sub CreateMemberInitExpression() Dim newAnimal As System.Linq.Expressions.NewExpression = _ System.Linq.Expressions.Expression.[New](Type.GetType("ExpressionVB.MemberInitExample+Animal")) Dim speciesMember As System.Reflection.MemberInfo = _ Type.GetType("ExpressionVB.MemberInitExample+Animal").GetMember("Species")(0) Dim ageMember As System.Reflection.MemberInfo = _ Type.GetType("ExpressionVB.MemberInitExample+Animal").GetMember("Age")(0) ' Create a MemberBinding object for each member ' that you want to initialize. Dim speciesMemberBinding As System.Linq.Expressions.MemberBinding = _ System.Linq.Expressions.Expression.Bind( _ speciesMember, _ System.Linq.Expressions.Expression.Constant("horse")) Dim ageMemberBinding As System.Linq.Expressions.MemberBinding = _ System.Linq.Expressions.Expression.Bind( _ ageMember, _ System.Linq.Expressions.Expression.Constant(12)) ' Create a MemberInitExpression that represents initializing ' two members of the 'Animal' class. Dim memberInitExpression As System.Linq.Expressions.MemberInitExpression = _ System.Linq.Expressions.Expression.MemberInit( _ newAnimal, _ speciesMemberBinding, _ ageMemberBinding) Console.WriteLine(memberInitExpression.ToString()) ' This code produces the following output: ' ' new Animal() {Species = "horse", Age = 12} End Sub
Windows 7, Windows Vista, Windows XP SP2, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003
The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Show: