Expression.New Método

Definição

Cria um NewExpression.Creates a NewExpression.

Sobrecargas

New(ConstructorInfo)

Cria um NewExpression que representa uma chamada ao construtor especificado que não aceita nenhum argumento.Creates a NewExpression that represents calling the specified constructor that takes no arguments.

New(Type)

Cria um NewExpression que representa uma chamada para o construtor sem parâmetro do tipo especificado.Creates a NewExpression that represents calling the parameterless constructor of the specified type.

New(ConstructorInfo, IEnumerable<Expression>)

Cria um NewExpression que representa uma chamada ao construtor especificado com os argumentos especificados.Creates a NewExpression that represents calling the specified constructor with the specified arguments.

New(ConstructorInfo, Expression[])

Cria um NewExpression que representa uma chamada ao construtor especificado com os argumentos especificados.Creates a NewExpression that represents calling the specified constructor with the specified arguments.

New(ConstructorInfo, IEnumerable<Expression>, IEnumerable<MemberInfo>)

Cria um NewExpression que representa uma chamada ao construtor especificado com os argumentos especificados.Creates a NewExpression that represents calling the specified constructor with the specified arguments. Os membros que acessam os campos inicializados pelo construtor são especificados.The members that access the constructor initialized fields are specified.

New(ConstructorInfo, IEnumerable<Expression>, MemberInfo[])

Cria um NewExpression que representa uma chamada ao construtor especificado com os argumentos especificados.Creates a NewExpression that represents calling the specified constructor with the specified arguments. Os membros que acessam os campos inicializados pelo construtor são especificados como uma matriz.The members that access the constructor initialized fields are specified as an array.

New(ConstructorInfo)

Cria um NewExpression que representa uma chamada ao construtor especificado que não aceita nenhum argumento.Creates a NewExpression that represents calling the specified constructor that takes no arguments.

public:
 static System::Linq::Expressions::NewExpression ^ New(System::Reflection::ConstructorInfo ^ constructor);
public static System.Linq.Expressions.NewExpression New (System.Reflection.ConstructorInfo constructor);
static member New : System.Reflection.ConstructorInfo -> System.Linq.Expressions.NewExpression
Public Shared Function New (constructor As ConstructorInfo) As NewExpression

Parâmetros

constructor
ConstructorInfo

O ConstructorInfo com um valor igual ao qual a Constructor propriedade será definida.The ConstructorInfo to set the Constructor property equal to.

Retornos

NewExpression

Uma NewExpression que tem a propriedade NodeType igual a New e a propriedade Constructor definida para o valor especificado.A NewExpression that has the NodeType property equal to New and the Constructor property set to the specified value.

Exceções

constructor é null.constructor is null.

O construtor representado por constructor tem pelo menos um parâmetro.The constructor that constructor represents has at least one parameter.

Comentários

As Arguments Members Propriedades e dos resultados NewExpression são coleções vazias.The Arguments and Members properties of the resulting NewExpression are empty collections. A Type propriedade representa o tipo declarativo do construtor representado por constructor .The Type property represents the declaring type of the constructor represented by constructor.

Aplica-se a

New(Type)

Cria um NewExpression que representa uma chamada para o construtor sem parâmetro do tipo especificado.Creates a NewExpression that represents calling the parameterless constructor of the specified type.

public:
 static System::Linq::Expressions::NewExpression ^ New(Type ^ type);
public static System.Linq.Expressions.NewExpression New (Type type);
static member New : Type -> System.Linq.Expressions.NewExpression
Public Shared Function New (type As Type) As NewExpression

Parâmetros

type
Type

Um Type contém um construtor que não aceita argumentos.A Type that has a constructor that takes no arguments.

Retornos

NewExpression

A NewExpression que tem a propriedade NodeType igual a New e a propriedade Constructor definida como o ConstructorInfo que representa o construtor sem parâmetros para o tipo especificado.A NewExpression that has the NodeType property equal to New and the Constructor property set to the ConstructorInfo that represents the constructor without parameters for the specified type.

Exceções

type é null.type is null.

O tipo que type representa não tem um construtor sem parâmetros.The type that type represents does not have a constructor without parameters.

Exemplos

O exemplo a seguir demonstra como usar o New(Type) método para criar um NewExpression que representa a construção de uma nova instância de um objeto Dictionary chamando o construtor sem parâmetros.The following example demonstrates how to use the New(Type) method to create a NewExpression that represents constructing a new instance of a dictionary object by calling the constructor without parameters.

// Create a NewExpression that represents constructing
// a new instance of Dictionary<int, string>.
System.Linq.Expressions.NewExpression newDictionaryExpression =
    System.Linq.Expressions.Expression.New(typeof(Dictionary<int, string>));

Console.WriteLine(newDictionaryExpression.ToString());

// This code produces the following output:
//
// new Dictionary`2()
' Create a NewExpression that represents constructing
' a new instance of Dictionary(Of Integer, String).
Dim newDictionaryExpression As System.Linq.Expressions.NewExpression = _
    System.Linq.Expressions.Expression.[New]( _
        Type.GetType("System.Collections.Generic.Dictionary`2[System.Int32, System.String]"))

Console.WriteLine(newDictionaryExpression.ToString())

' This code produces the following output:
'
' new Dictionary`2()

Comentários

O type parâmetro deve representar um tipo que tenha um construtor sem parâmetros.The type parameter must represent a type that has a constructor without parameters.

As Arguments Members Propriedades e dos resultados NewExpression são coleções vazias.The Arguments and Members properties of the resulting NewExpression are empty collections. A Type propriedade é igual a type .The Type property is equal to type.

Aplica-se a

New(ConstructorInfo, IEnumerable<Expression>)

Cria um NewExpression que representa uma chamada ao construtor especificado com os argumentos especificados.Creates a NewExpression that represents calling the specified constructor with the specified arguments.

public:
 static System::Linq::Expressions::NewExpression ^ New(System::Reflection::ConstructorInfo ^ constructor, System::Collections::Generic::IEnumerable<System::Linq::Expressions::Expression ^> ^ arguments);
public static System.Linq.Expressions.NewExpression New (System.Reflection.ConstructorInfo constructor, System.Collections.Generic.IEnumerable<System.Linq.Expressions.Expression> arguments);
public static System.Linq.Expressions.NewExpression New (System.Reflection.ConstructorInfo constructor, System.Collections.Generic.IEnumerable<System.Linq.Expressions.Expression>? arguments);
static member New : System.Reflection.ConstructorInfo * seq<System.Linq.Expressions.Expression> -> System.Linq.Expressions.NewExpression
Public Shared Function New (constructor As ConstructorInfo, arguments As IEnumerable(Of Expression)) As NewExpression

Parâmetros

constructor
ConstructorInfo

O ConstructorInfo com um valor igual ao qual a Constructor propriedade será definida.The ConstructorInfo to set the Constructor property equal to.

arguments
IEnumerable<Expression>

Um IEnumerable<T> que contém objetos Expression a serem usados para preencher a coleção de Arguments.An IEnumerable<T> that contains Expression objects to use to populate the Arguments collection.

Retornos

NewExpression

Um NewExpression que tem a propriedade NodeType igual a New e as propriedades Constructor e Arguments definidas com os valores especificados.A NewExpression that has the NodeType property equal to New and the Constructor and Arguments properties set to the specified values.

Exceções

constructor é null.constructor is null.

- ou --or- Um elemento de arguments é null.An element of arguments is null.

O parâmetro arguments não contém o mesmo número de elementos que o número de parâmetros do construtor representado por constructor.The arguments parameter does not contain the same number of elements as the number of parameters for the constructor that constructor represents.

- ou --or- A propriedade Type de um elemento de arguments não pode ser atribuída ao tipo do parâmetro correspondente do construtor representado por constructor.The Type property of an element of arguments is not assignable to the type of the corresponding parameter of the constructor that constructor represents.

Comentários

O arguments parâmetro deve conter o mesmo número de elementos que o número de parâmetros para o construtor representado por constructor .The arguments parameter must contain the same number of elements as the number of parameters for the constructor represented by constructor. Se arguments for null , ele será considerado vazio e a Arguments Propriedade do resultante NewExpression será uma coleção vazia.If arguments is null, it is considered empty, and the Arguments property of the resulting NewExpression is an empty collection.

A Type Propriedade do resultante NewExpression representa o tipo declarativo do construtor representado por constructor .The Type property of the resulting NewExpression represents the declaring type of the constructor represented by constructor. A Members propriedade é uma coleção vazia.The Members property is an empty collection.

Aplica-se a

New(ConstructorInfo, Expression[])

Cria um NewExpression que representa uma chamada ao construtor especificado com os argumentos especificados.Creates a NewExpression that represents calling the specified constructor with the specified arguments.

public:
 static System::Linq::Expressions::NewExpression ^ New(System::Reflection::ConstructorInfo ^ constructor, ... cli::array <System::Linq::Expressions::Expression ^> ^ arguments);
public static System.Linq.Expressions.NewExpression New (System.Reflection.ConstructorInfo constructor, params System.Linq.Expressions.Expression[] arguments);
public static System.Linq.Expressions.NewExpression New (System.Reflection.ConstructorInfo constructor, params System.Linq.Expressions.Expression[]? arguments);
static member New : System.Reflection.ConstructorInfo * System.Linq.Expressions.Expression[] -> System.Linq.Expressions.NewExpression
Public Shared Function New (constructor As ConstructorInfo, ParamArray arguments As Expression()) As NewExpression

Parâmetros

constructor
ConstructorInfo

O ConstructorInfo com um valor igual ao qual a Constructor propriedade será definida.The ConstructorInfo to set the Constructor property equal to.

arguments
Expression[]

Uma matriz de objetos Expression a serem usados para popular a coleção de Arguments.An array of Expression objects to use to populate the Arguments collection.

Retornos

NewExpression

Um NewExpression que tem a propriedade NodeType igual a New e as propriedades Constructor e Arguments definidas com os valores especificados.A NewExpression that has the NodeType property equal to New and the Constructor and Arguments properties set to the specified values.

Exceções

constructor é null.constructor is null.

- ou --or- Um elemento de arguments é null.An element of arguments is null.

O tamanho de arguments corresponde ao número de parâmetros do construtor representado por constructor.The length of arguments does match the number of parameters for the constructor that constructor represents.

- ou --or- A propriedade Type de um elemento de arguments não pode ser atribuída ao tipo do parâmetro correspondente do construtor representado por constructor.The Type property of an element of arguments is not assignable to the type of the corresponding parameter of the constructor that constructor represents.

Comentários

O arguments parâmetro deve conter o mesmo número de elementos que o número de parâmetros para o construtor representado por constructor .The arguments parameter must contain the same number of elements as the number of parameters for the constructor represented by constructor. Se arguments for null , ele será considerado vazio e a Arguments Propriedade do resultante NewExpression será uma coleção vazia.If arguments is null, it is considered empty, and the Arguments property of the resulting NewExpression is an empty collection.

A Type Propriedade do resultante NewExpression representa o tipo declarativo do construtor representado por constructor .The Type property of the resulting NewExpression represents the declaring type of the constructor represented by constructor. A Members propriedade é uma coleção vazia.The Members property is an empty collection.

Aplica-se a

New(ConstructorInfo, IEnumerable<Expression>, IEnumerable<MemberInfo>)

Cria um NewExpression que representa uma chamada ao construtor especificado com os argumentos especificados.Creates a NewExpression that represents calling the specified constructor with the specified arguments. Os membros que acessam os campos inicializados pelo construtor são especificados.The members that access the constructor initialized fields are specified.

public:
 static System::Linq::Expressions::NewExpression ^ New(System::Reflection::ConstructorInfo ^ constructor, System::Collections::Generic::IEnumerable<System::Linq::Expressions::Expression ^> ^ arguments, System::Collections::Generic::IEnumerable<System::Reflection::MemberInfo ^> ^ members);
public static System.Linq.Expressions.NewExpression New (System.Reflection.ConstructorInfo constructor, System.Collections.Generic.IEnumerable<System.Linq.Expressions.Expression> arguments, System.Collections.Generic.IEnumerable<System.Reflection.MemberInfo> members);
public static System.Linq.Expressions.NewExpression New (System.Reflection.ConstructorInfo constructor, System.Collections.Generic.IEnumerable<System.Linq.Expressions.Expression>? arguments, System.Collections.Generic.IEnumerable<System.Reflection.MemberInfo>? members);
static member New : System.Reflection.ConstructorInfo * seq<System.Linq.Expressions.Expression> * seq<System.Reflection.MemberInfo> -> System.Linq.Expressions.NewExpression
Public Shared Function New (constructor As ConstructorInfo, arguments As IEnumerable(Of Expression), members As IEnumerable(Of MemberInfo)) As NewExpression

Parâmetros

constructor
ConstructorInfo

O ConstructorInfo com um valor igual ao qual a Constructor propriedade será definida.The ConstructorInfo to set the Constructor property equal to.

arguments
IEnumerable<Expression>

Um IEnumerable<T> que contém objetos Expression a serem usados para preencher a coleção de Arguments.An IEnumerable<T> that contains Expression objects to use to populate the Arguments collection.

members
IEnumerable<MemberInfo>

Um IEnumerable<T> que contém objetos MemberInfo a serem usados para preencher a coleção de Members.An IEnumerable<T> that contains MemberInfo objects to use to populate the Members collection.

Retornos

NewExpression

Um NewExpression que tem a propriedade NodeType igual a New e as propriedades Constructor, Arguments e Members definidas para os valores especificados.A NewExpression that has the NodeType property equal to New and the Constructor, Arguments and Members properties set to the specified values.

Exceções

constructor é null.constructor is null.

- ou --or- Um elemento de arguments é null.An element of arguments is null.

- ou --or- Um elemento de members é null.An element of members is null.

O parâmetro arguments não contém o mesmo número de elementos que o número de parâmetros do construtor representado por constructor.The arguments parameter does not contain the same number of elements as the number of parameters for the constructor that constructor represents.

- ou --or- A propriedade Type de um elemento de arguments não pode ser atribuída ao tipo do parâmetro correspondente do construtor representado por constructor.The Type property of an element of arguments is not assignable to the type of the corresponding parameter of the constructor that constructor represents.

- ou --or- O parâmetro members não tem o mesmo número de elementos de arguments.The members parameter does not have the same number of elements as arguments.

- ou --or- Um elemento de arguments tem uma propriedade Type que representa um tipo que não é atribuível ao tipo do membro que é representado pelo elemento correspondente de members.An element of arguments has a Type property that represents a type that is not assignable to the type of the member that is represented by the corresponding element of members.

Comentários

O arguments parâmetro deve conter o mesmo número de elementos que o número de parâmetros para o construtor representado por constructor .The arguments parameter must contain the same number of elements as the number of parameters for the constructor represented by constructor. Se arguments for null , ele será considerado vazio e a Arguments Propriedade do resultante NewExpression será uma coleção vazia.If arguments is null, it is considered empty, and the Arguments property of the resulting NewExpression is an empty collection.

Se members for null , a Members Propriedade do resultante NewExpression será uma coleção vazia.If members is null, the Members property of the resulting NewExpression is an empty collection. Se members não for null , ele deve ter o mesmo número de elementos que arguments e cada elemento não deve ser null .If members is not null, it must have the same number of elements as arguments and each element must not be null. Cada elemento de members deve ser um PropertyInfo FieldInfo ou MethodInfo que representa um membro de instância no tipo declarativo do construtor representado por constructor .Each element of members must be a PropertyInfo, FieldInfo or MethodInfo that represents an instance member on the declaring type of the constructor represented by constructor. Se representar uma propriedade, a propriedade deverá ter um get acessador.If it represents a property, the property must have a get accessor. O elemento correspondente de arguments para cada elemento de members deve ter uma Type propriedade que representa um tipo que pode ser atribuído ao tipo do membro que o members elemento representa.The corresponding element of arguments for each element of members must have a Type property that represents a type that is assignable to the type of the member that the members element represents.

A Type Propriedade do resultante NewExpression representa o tipo declarativo do construtor que constructor representa.The Type property of the resulting NewExpression represents the declaring type of the constructor that constructor represents.

Aplica-se a

New(ConstructorInfo, IEnumerable<Expression>, MemberInfo[])

Cria um NewExpression que representa uma chamada ao construtor especificado com os argumentos especificados.Creates a NewExpression that represents calling the specified constructor with the specified arguments. Os membros que acessam os campos inicializados pelo construtor são especificados como uma matriz.The members that access the constructor initialized fields are specified as an array.

public:
 static System::Linq::Expressions::NewExpression ^ New(System::Reflection::ConstructorInfo ^ constructor, System::Collections::Generic::IEnumerable<System::Linq::Expressions::Expression ^> ^ arguments, ... cli::array <System::Reflection::MemberInfo ^> ^ members);
public static System.Linq.Expressions.NewExpression New (System.Reflection.ConstructorInfo constructor, System.Collections.Generic.IEnumerable<System.Linq.Expressions.Expression> arguments, params System.Reflection.MemberInfo[] members);
public static System.Linq.Expressions.NewExpression New (System.Reflection.ConstructorInfo constructor, System.Collections.Generic.IEnumerable<System.Linq.Expressions.Expression>? arguments, params System.Reflection.MemberInfo[]? members);
static member New : System.Reflection.ConstructorInfo * seq<System.Linq.Expressions.Expression> * System.Reflection.MemberInfo[] -> System.Linq.Expressions.NewExpression
Public Shared Function New (constructor As ConstructorInfo, arguments As IEnumerable(Of Expression), ParamArray members As MemberInfo()) As NewExpression

Parâmetros

constructor
ConstructorInfo

O ConstructorInfo com um valor igual ao qual a Constructor propriedade será definida.The ConstructorInfo to set the Constructor property equal to.

arguments
IEnumerable<Expression>

Um IEnumerable<T> que contém objetos Expression a serem usados para preencher a coleção de Arguments.An IEnumerable<T> that contains Expression objects to use to populate the Arguments collection.

members
MemberInfo[]

Uma matriz de objetos MemberInfo a serem usados para popular a coleção de Members.An array of MemberInfo objects to use to populate the Members collection.

Retornos

NewExpression

Um NewExpression que tem a propriedade NodeType igual a New e as propriedades Constructor, Arguments e Members definidas para os valores especificados.A NewExpression that has the NodeType property equal to New and the Constructor, Arguments and Members properties set to the specified values.

Exceções

constructor é null.constructor is null.

- ou --or- Um elemento de arguments é null.An element of arguments is null.

- ou --or- Um elemento de members é null.An element of members is null.

O parâmetro arguments não contém o mesmo número de elementos que o número de parâmetros do construtor representado por constructor.The arguments parameter does not contain the same number of elements as the number of parameters for the constructor that constructor represents.

- ou --or- A propriedade Type de um elemento de arguments não pode ser atribuída ao tipo do parâmetro correspondente do construtor representado por constructor.The Type property of an element of arguments is not assignable to the type of the corresponding parameter of the constructor that constructor represents.

- ou --or- O parâmetro members não tem o mesmo número de elementos de arguments.The members parameter does not have the same number of elements as arguments.

- ou --or- Um elemento de arguments tem uma propriedade Type que representa um tipo que não é atribuível ao tipo do membro que é representado pelo elemento correspondente de members.An element of arguments has a Type property that represents a type that is not assignable to the type of the member that is represented by the corresponding element of members.

Comentários

O arguments parâmetro deve conter o mesmo número de elementos que o número de parâmetros para o construtor representado por constructor .The arguments parameter must contain the same number of elements as the number of parameters for the constructor represented by constructor. Se arguments for null , ele será considerado vazio e a Arguments Propriedade do resultante NewExpression será uma coleção vazia.If arguments is null, it is considered empty, and the Arguments property of the resulting NewExpression is an empty collection.

Se members for null , a Members Propriedade do resultante NewExpression será uma coleção vazia.If members is null, the Members property of the resulting NewExpression is an empty collection. Se members não for null , ele deve ter o mesmo número de elementos que arguments e cada elemento não deve ser null .If members is not null, it must have the same number of elements as arguments and each element must not be null. Cada elemento de members deve ser um PropertyInfo FieldInfo ou MethodInfo que representa um membro de instância no tipo declarativo do construtor representado por constructor .Each element of members must be a PropertyInfo, FieldInfo or MethodInfo that represents an instance member on the declaring type of the constructor represented by constructor. Se representar uma propriedade, a propriedade deverá ser capaz de recuperar o valor do campo associado.If it represents a property, the property must be able to retrieve the value of the associated field. O elemento correspondente de arguments para cada elemento de members deve ter uma Type propriedade que representa um tipo que pode ser atribuído ao tipo do membro que o members elemento representa.The corresponding element of arguments for each element of members must have a Type property that represents a type that is assignable to the type of the member that the members element represents.

A Type Propriedade do resultante NewExpression representa o tipo declarativo do construtor que constructor representa.The Type property of the resulting NewExpression represents the declaring type of the constructor that constructor represents.

Aplica-se a