Expression.Invoke Método

Definição

Sobrecargas

Invoke(Expression, Expression[])

Cria um InvocationExpression que se aplica a uma expressão de delegado ou lambda para uma lista de expressões de argumento.Creates an InvocationExpression that applies a delegate or lambda expression to a list of argument expressions.

Invoke(Expression, IEnumerable<Expression>)

Cria um InvocationExpression que se aplica a uma expressão de delegado ou lambda para uma lista de expressões de argumento.Creates an InvocationExpression that applies a delegate or lambda expression to a list of argument expressions.

Invoke(Expression, Expression[])

Cria um InvocationExpression que se aplica a uma expressão de delegado ou lambda para uma lista de expressões de argumento.Creates an InvocationExpression that applies a delegate or lambda expression to a list of argument expressions.

public:
 static System::Linq::Expressions::InvocationExpression ^ Invoke(System::Linq::Expressions::Expression ^ expression, ... cli::array <System::Linq::Expressions::Expression ^> ^ arguments);
public static System.Linq.Expressions.InvocationExpression Invoke (System.Linq.Expressions.Expression expression, params System.Linq.Expressions.Expression[] arguments);
public static System.Linq.Expressions.InvocationExpression Invoke (System.Linq.Expressions.Expression expression, params System.Linq.Expressions.Expression[]? arguments);
static member Invoke : System.Linq.Expressions.Expression * System.Linq.Expressions.Expression[] -> System.Linq.Expressions.InvocationExpression
Public Shared Function Invoke (expression As Expression, ParamArray arguments As Expression()) As InvocationExpression

Parâmetros

expression
Expression

Um Expression que representa a expressão de delegado ou lambda a ser aplicada.An Expression that represents the delegate or lambda expression to be applied.

arguments
Expression[]

Uma matriz de objetos Expression que representam os argumentos aos quais que a expressão de delegado ou lambda são aplicados.An array of Expression objects that represent the arguments that the delegate or lambda expression is applied to.

Retornos

InvocationExpression

Um InvocationExpression que se aplica à expressão de delegado ou lambda especificada para os argumentos fornecidos.An InvocationExpression that applies the specified delegate or lambda expression to the provided arguments.

Exceções

expression é null.expression is null.

expression.Type não representa um tipo de delegado nem um Expression<TDelegate>.expression.Type does not represent a delegate type or an Expression<TDelegate>.

- ou --or- A propriedade Type de um elemento de arguments não é atribuível ao tipo de parâmetro correspondente ao delegado representado por expression.The Type property of an element of arguments is not assignable to the type of the corresponding parameter of the delegate represented by expression.

arguments não contém o mesmo número de elementos da lista de parâmetros para o delegado representado por expression.arguments does not contain the same number of elements as the list of parameters for the delegate represented by expression.

Exemplos

O exemplo a seguir demonstra como usar o Invoke(Expression, Expression[]) método para criar um InvocationExpression que representa a invocação de uma expressão lambda com argumentos especificados.The following example demonstrates how to use the Invoke(Expression, Expression[]) method to create an InvocationExpression that represents the invocation of a lambda expression with specified arguments.

System.Linq.Expressions.Expression<Func<int, int, bool>> largeSumTest =
    (num1, num2) => (num1 + num2) > 1000;

// Create an InvocationExpression that represents applying
// the arguments '539' and '281' to the lambda expression 'largeSumTest'.
System.Linq.Expressions.InvocationExpression invocationExpression =
    System.Linq.Expressions.Expression.Invoke(
        largeSumTest,
        System.Linq.Expressions.Expression.Constant(539),
        System.Linq.Expressions.Expression.Constant(281));

Console.WriteLine(invocationExpression.ToString());

// This code produces the following output:
//
// Invoke((num1, num2) => ((num1 + num2) > 1000),539,281)
Dim largeSumTest As System.Linq.Expressions.Expression(Of System.Func(Of Integer, Integer, Boolean)) = _
    Function(num1, num2) (num1 + num2) > 1000

' Create an InvocationExpression that represents applying
' the arguments '539' and '281' to the lambda expression 'largeSumTest'.
Dim invocationExpression As System.Linq.Expressions.InvocationExpression = _
    System.Linq.Expressions.Expression.Invoke( _
        largeSumTest, _
        System.Linq.Expressions.Expression.Constant(539), _
        System.Linq.Expressions.Expression.Constant(281))

Console.WriteLine(invocationExpression.ToString())

' This code produces the following output:
'
' Invoke((num1, num2) => ((num1 + num2) > 1000),539,281)

Comentários

A Type Propriedade do resultante InvocationExpression representa o tipo de retorno do delegado que é representado por expression . Escreva.The Type property of the resulting InvocationExpression represents the return type of the delegate that is represented by expression.Type.

A Arguments Propriedade do resultante InvocationExpression será vazia se arguments for null .The Arguments property of the resulting InvocationExpression is empty if arguments is null. Caso contrário, ele contém os mesmos elementos, arguments exceto que alguns desses Expression objetos podem estar entre aspas.Otherwise, it contains the same elements as arguments except that some of these Expression objects may be quoted.

Observação

Um elemento será citado somente se o parâmetro correspondente do delegado representado por expression for do tipo Expression .An element will be quoted only if the corresponding parameter of the delegate represented by expression is of type Expression. A cotação significa que o elemento é encapsulado em um Quote nó.Quoting means the element is wrapped in a Quote node. O nó resultante é um UnaryExpression cuja Operand propriedade é o elemento de arguments .The resulting node is a UnaryExpression whose Operand property is the element of arguments.

Aplica-se a

Invoke(Expression, IEnumerable<Expression>)

Cria um InvocationExpression que se aplica a uma expressão de delegado ou lambda para uma lista de expressões de argumento.Creates an InvocationExpression that applies a delegate or lambda expression to a list of argument expressions.

public:
 static System::Linq::Expressions::InvocationExpression ^ Invoke(System::Linq::Expressions::Expression ^ expression, System::Collections::Generic::IEnumerable<System::Linq::Expressions::Expression ^> ^ arguments);
public static System.Linq.Expressions.InvocationExpression Invoke (System.Linq.Expressions.Expression expression, System.Collections.Generic.IEnumerable<System.Linq.Expressions.Expression> arguments);
public static System.Linq.Expressions.InvocationExpression Invoke (System.Linq.Expressions.Expression expression, System.Collections.Generic.IEnumerable<System.Linq.Expressions.Expression>? arguments);
static member Invoke : System.Linq.Expressions.Expression * seq<System.Linq.Expressions.Expression> -> System.Linq.Expressions.InvocationExpression
Public Shared Function Invoke (expression As Expression, arguments As IEnumerable(Of Expression)) As InvocationExpression

Parâmetros

expression
Expression

Um Expression que representa a expressão de delegado ou lambda à qual aplicar.An Expression that represents the delegate or lambda expression to be applied to.

arguments
IEnumerable<Expression>

Um IEnumerable<T> que contém objetos Expression que representam os argumentos aos quais a expressão de delegado ou lambda é aplicada.An IEnumerable<T> that contains Expression objects that represent the arguments that the delegate or lambda expression is applied to.

Retornos

InvocationExpression

Um InvocationExpression que se aplica à expressão de delegado ou lambda especificada para os argumentos fornecidos.An InvocationExpression that applies the specified delegate or lambda expression to the provided arguments.

Exceções

expression é null.expression is null.

expression.Type não representa um tipo de delegado nem um Expression<TDelegate>.expression.Type does not represent a delegate type or an Expression<TDelegate>.

- ou --or- A propriedade Type de um elemento de arguments não é atribuível ao tipo de parâmetro correspondente ao delegado representado por expression.The Type property of an element of arguments is not assignable to the type of the corresponding parameter of the delegate represented by expression.

arguments não contém o mesmo número de elementos da lista de parâmetros para o delegado representado por expression.arguments does not contain the same number of elements as the list of parameters for the delegate represented by expression.

Exemplos

O exemplo a seguir demonstra como usar o Invoke(Expression, Expression[]) método para criar um InvocationExpression que representa a invocação de uma expressão lambda com argumentos especificados.The following example demonstrates how to use the Invoke(Expression, Expression[]) method to create an InvocationExpression that represents the invocation of a lambda expression with specified arguments.

System.Linq.Expressions.Expression<Func<int, int, bool>> largeSumTest =
    (num1, num2) => (num1 + num2) > 1000;

// Create an InvocationExpression that represents applying
// the arguments '539' and '281' to the lambda expression 'largeSumTest'.
System.Linq.Expressions.InvocationExpression invocationExpression =
    System.Linq.Expressions.Expression.Invoke(
        largeSumTest,
        System.Linq.Expressions.Expression.Constant(539),
        System.Linq.Expressions.Expression.Constant(281));

Console.WriteLine(invocationExpression.ToString());

// This code produces the following output:
//
// Invoke((num1, num2) => ((num1 + num2) > 1000),539,281)
Dim largeSumTest As System.Linq.Expressions.Expression(Of System.Func(Of Integer, Integer, Boolean)) = _
    Function(num1, num2) (num1 + num2) > 1000

' Create an InvocationExpression that represents applying
' the arguments '539' and '281' to the lambda expression 'largeSumTest'.
Dim invocationExpression As System.Linq.Expressions.InvocationExpression = _
    System.Linq.Expressions.Expression.Invoke( _
        largeSumTest, _
        System.Linq.Expressions.Expression.Constant(539), _
        System.Linq.Expressions.Expression.Constant(281))

Console.WriteLine(invocationExpression.ToString())

' This code produces the following output:
'
' Invoke((num1, num2) => ((num1 + num2) > 1000),539,281)

Comentários

A Type Propriedade do resultante InvocationExpression representa o tipo de retorno do delegado que é representado por expression . Escreva.The Type property of the resulting InvocationExpression represents the return type of the delegate that is represented by expression.Type.

A Arguments Propriedade do resultante InvocationExpression será vazia se arguments for null .The Arguments property of the resulting InvocationExpression is empty if arguments is null. Caso contrário, ele contém os mesmos elementos, arguments exceto que alguns desses Expression objetos podem estar entre aspas.Otherwise, it contains the same elements as arguments except that some of these Expression objects may be quoted.

Observação

Um elemento será citado somente se o parâmetro correspondente do delegado representado por expression for do tipo Expression .An element will be quoted only if the corresponding parameter of the delegate represented by expression is of type Expression. A cotação significa que o elemento é encapsulado em um Quote nó.Quoting means the element is wrapped in a Quote node. O nó resultante é um UnaryExpression cuja Operand propriedade é o elemento de arguments .The resulting node is a UnaryExpression whose Operand property is the element of arguments.

Aplica-se a