Expression.Call メソッド
定義
重要
一部の情報は、リリース前に大きく変更される可能性があるプレリリースされた製品に関するものです。 Microsoft は、ここに記載されている情報について、明示または黙示を問わず、一切保証しません。
MethodCallExpressionを作成します。
オーバーロード
Call(MethodInfo, Expression, Expression, Expression, Expression, Expression)
5 つの引数を受け取る静的メソッドの呼び出しを表す MethodCallExpression を作成します。
public:
static System::Linq::Expressions::MethodCallExpression ^ Call(System::Reflection::MethodInfo ^ method, System::Linq::Expressions::Expression ^ arg0, System::Linq::Expressions::Expression ^ arg1, System::Linq::Expressions::Expression ^ arg2, System::Linq::Expressions::Expression ^ arg3, System::Linq::Expressions::Expression ^ arg4);
public static System.Linq.Expressions.MethodCallExpression Call(System.Reflection.MethodInfo method, System.Linq.Expressions.Expression arg0, System.Linq.Expressions.Expression arg1, System.Linq.Expressions.Expression arg2, System.Linq.Expressions.Expression arg3, System.Linq.Expressions.Expression arg4);
static member Call : System.Reflection.MethodInfo * System.Linq.Expressions.Expression * System.Linq.Expressions.Expression * System.Linq.Expressions.Expression * System.Linq.Expressions.Expression * System.Linq.Expressions.Expression -> System.Linq.Expressions.MethodCallExpression
Public Shared Function Call (method As MethodInfo, arg0 As Expression, arg1 As Expression, arg2 As Expression, arg3 As Expression, arg4 As Expression) As MethodCallExpression
パラメーター
- method
- MethodInfo
MethodInfo プロパティを等しく設定するMethod。
- arg0
- Expression
最初の引数を表す Expression 。
- arg1
- Expression
2 番目の引数を表す Expression 。
- arg2
- Expression
3 番目の引数を表す Expression 。
- arg3
- Expression
4 番目の引数を表す Expression 。
- arg4
- Expression
5 番目の引数を表す Expression 。
返品
MethodCallExpression プロパティが NodeType と等しく、CallプロパティとObjectプロパティが指定した値に設定されているMethod。
例外
method が null です。
適用対象
Call(Expression, MethodInfo, Expression, Expression, Expression)
3 つの引数を受け取るメソッドの呼び出しを表す MethodCallExpression を作成します。
public:
static System::Linq::Expressions::MethodCallExpression ^ Call(System::Linq::Expressions::Expression ^ instance, System::Reflection::MethodInfo ^ method, System::Linq::Expressions::Expression ^ arg0, System::Linq::Expressions::Expression ^ arg1, System::Linq::Expressions::Expression ^ arg2);
public static System.Linq.Expressions.MethodCallExpression Call(System.Linq.Expressions.Expression instance, System.Reflection.MethodInfo method, System.Linq.Expressions.Expression arg0, System.Linq.Expressions.Expression arg1, System.Linq.Expressions.Expression arg2);
static member Call : System.Linq.Expressions.Expression * System.Reflection.MethodInfo * System.Linq.Expressions.Expression * System.Linq.Expressions.Expression * System.Linq.Expressions.Expression -> System.Linq.Expressions.MethodCallExpression
Public Shared Function Call (instance As Expression, method As MethodInfo, arg0 As Expression, arg1 As Expression, arg2 As Expression) As MethodCallExpression
パラメーター
- instance
- Expression
インスタンス呼び出しのインスタンスを指定する Expression 。 (静的 (Visual Basic では共有) メソッドには null を渡します)。
- method
- MethodInfo
ターゲット メソッドを表す MethodInfo 。
- arg0
- Expression
最初の引数を表す Expression 。
- arg1
- Expression
2 番目の引数を表す Expression 。
- arg2
- Expression
3 番目の引数を表す Expression 。
返品
MethodCallExpression プロパティが NodeType と等しく、CallプロパティとObjectプロパティが指定した値に設定されているMethod。
適用対象
Call(Type, String, Type[], Expression[])
適切なファクトリ メソッドを呼び出して、MethodCallExpression (Visual Basic のstatic) メソッドの呼び出しを表すSharedを作成します。
public:
static System::Linq::Expressions::MethodCallExpression ^ Call(Type ^ type, System::String ^ methodName, cli::array <Type ^> ^ typeArguments, ... cli::array <System::Linq::Expressions::Expression ^> ^ arguments);
public static System.Linq.Expressions.MethodCallExpression Call(Type type, string methodName, Type[] typeArguments, params System.Linq.Expressions.Expression[] arguments);
static member Call : Type * string * Type[] * System.Linq.Expressions.Expression[] -> System.Linq.Expressions.MethodCallExpression
Public Shared Function Call (type As Type, methodName As String, typeArguments As Type(), ParamArray arguments As Expression()) As MethodCallExpression
パラメーター
- type
- Type
指定した static (Visual Basic のShared ) メソッドを含む型。
- methodName
- String
メソッドの名前。
- typeArguments
- Type[]
ジェネリック メソッドの型パラメーターを指定する Type オブジェクトの配列。 methodName が非ジェネリック メソッドを指定する場合、この引数は null にする必要があります。
- arguments
- Expression[]
メソッドの引数 Expression 表すオブジェクトの配列。
返品
MethodCallExpression プロパティが NodeType と等しいCall、指定したMethod (Visual Basic のMethodInfo) を表すstaticに設定されたShared プロパティ、および指定した引数に設定されたArguments プロパティ。
例外
type または methodName が null。
名前が methodName、型パラメーターが typeArgumentsに一致し、パラメーター型が arguments と一致するメソッドは、 type またはその基本型に見つかりません。
-または-
名前が methodNameで、型パラメーターが typeArgumentsに一致し、パラメーター型が arguments と一致する複数のメソッドが、 type またはその基本型で見つかります。
注釈
結果のTypeのMethodCallExpressionプロパティは、methodNameで示されるメソッドの戻り値の型と等しくなります。
Object プロパティはnull。
適用対象
Call(MethodInfo, Expression, Expression, Expression)
3 つの引数を受け取る静的メソッドの呼び出しを表す MethodCallExpression を作成します。
public:
static System::Linq::Expressions::MethodCallExpression ^ Call(System::Reflection::MethodInfo ^ method, System::Linq::Expressions::Expression ^ arg0, System::Linq::Expressions::Expression ^ arg1, System::Linq::Expressions::Expression ^ arg2);
public static System.Linq.Expressions.MethodCallExpression Call(System.Reflection.MethodInfo method, System.Linq.Expressions.Expression arg0, System.Linq.Expressions.Expression arg1, System.Linq.Expressions.Expression arg2);
static member Call : System.Reflection.MethodInfo * System.Linq.Expressions.Expression * System.Linq.Expressions.Expression * System.Linq.Expressions.Expression -> System.Linq.Expressions.MethodCallExpression
Public Shared Function Call (method As MethodInfo, arg0 As Expression, arg1 As Expression, arg2 As Expression) As MethodCallExpression
パラメーター
- method
- MethodInfo
MethodInfo プロパティを等しく設定するMethod。
- arg0
- Expression
最初の引数を表す Expression 。
- arg1
- Expression
2 番目の引数を表す Expression 。
- arg2
- Expression
3 番目の引数を表す Expression 。
返品
MethodCallExpression プロパティが NodeType と等しく、CallプロパティとObjectプロパティが指定した値に設定されているMethod。
例外
method が null です。
適用対象
Call(Expression, String, Type[], Expression[])
適切なファクトリ メソッドを呼び出して、メソッドの呼び出しを表す MethodCallExpression を作成します。
public:
static System::Linq::Expressions::MethodCallExpression ^ Call(System::Linq::Expressions::Expression ^ instance, System::String ^ methodName, cli::array <Type ^> ^ typeArguments, ... cli::array <System::Linq::Expressions::Expression ^> ^ arguments);
public static System.Linq.Expressions.MethodCallExpression Call(System.Linq.Expressions.Expression instance, string methodName, Type[] typeArguments, params System.Linq.Expressions.Expression[] arguments);
static member Call : System.Linq.Expressions.Expression * string * Type[] * System.Linq.Expressions.Expression[] -> System.Linq.Expressions.MethodCallExpression
Public Shared Function Call (instance As Expression, methodName As String, typeArguments As Type(), ParamArray arguments As Expression()) As MethodCallExpression
パラメーター
- instance
- Expression
Expressionプロパティ値が特定のメソッドを検索するType。
- methodName
- String
メソッドの名前。
- typeArguments
- Type[]
ジェネリック メソッドの型パラメーターを指定する Type オブジェクトの配列。 methodName が非ジェネリック メソッドを指定する場合、この引数は null にする必要があります。
- arguments
- Expression[]
メソッドの引数を表す Expression オブジェクトの配列。
返品
MethodCallExpression プロパティが NodeType と等しく、Call プロパティが Object に等しい、指定したインスタンス メソッドを表すinstanceに設定Method、指定した引数に設定MethodInfoArguments。
例外
instance または methodName が null。
名前が methodName、型パラメーターが typeArgumentsに一致し、パラメーター型が arguments に一致するメソッドが instanceに見つかりません。型またはその基本型。
-または-
名前が methodNameで、型パラメーターが typeArgumentsに一致し、パラメーター型が arguments と一致する複数のメソッドが instanceにあります。型またはその基本型。
注釈
結果のTypeのMethodCallExpressionプロパティは、methodNameで示されるメソッドの戻り値の型と等しくなります。
適用対象
Call(Expression, MethodInfo, Expression, Expression)
2 つの引数を受け取るメソッドの呼び出しを表す MethodCallExpression を作成します。
public:
static System::Linq::Expressions::MethodCallExpression ^ Call(System::Linq::Expressions::Expression ^ instance, System::Reflection::MethodInfo ^ method, System::Linq::Expressions::Expression ^ arg0, System::Linq::Expressions::Expression ^ arg1);
public static System.Linq.Expressions.MethodCallExpression Call(System.Linq.Expressions.Expression instance, System.Reflection.MethodInfo method, System.Linq.Expressions.Expression arg0, System.Linq.Expressions.Expression arg1);
static member Call : System.Linq.Expressions.Expression * System.Reflection.MethodInfo * System.Linq.Expressions.Expression * System.Linq.Expressions.Expression -> System.Linq.Expressions.MethodCallExpression
Public Shared Function Call (instance As Expression, method As MethodInfo, arg0 As Expression, arg1 As Expression) As MethodCallExpression
パラメーター
- instance
- Expression
インスタンス呼び出しのインスタンスを指定する Expression 。 (静的 (Visual Basic では共有) メソッドには null を渡します)。
- method
- MethodInfo
ターゲット メソッドを表す MethodInfo 。
- arg0
- Expression
最初の引数を表す Expression 。
- arg1
- Expression
2 番目の引数を表す Expression 。
返品
MethodCallExpression プロパティが NodeType と等しく、CallプロパティとObjectプロパティが指定した値に設定されているMethod。
例
次のコード例は、2 つの引数を持つインスタンス メソッドを呼び出す式を作成する方法を示しています。
// Add the following directive to your file:
// using System.Linq.Expressions;
public class SampleClass
{
public int AddIntegers(int arg1, int arg2)
{
return arg1 + arg2;
}
}
static public void TestCall()
{
// This expression represents a call to an instance method that has two arguments.
// The first argument is an expression that creates a new object of the specified type.
Expression callExpr = Expression.Call(
Expression.New(typeof(SampleClass)),
typeof(SampleClass).GetMethod("AddIntegers", new Type[] { typeof(int), typeof(int) }),
Expression.Constant(1),
Expression.Constant(2)
);
// Print out the expression.
Console.WriteLine(callExpr.ToString());
// The following statement first creates an expression tree,
// then compiles it, and then executes it.
Console.WriteLine(Expression.Lambda<Func<int>>(callExpr).Compile()());
// This code example produces the following output:
//
// new SampleClass().AddIntegers(1, 2)
// 3
}
' Add the following directive to your file:
' Imports System.Linq.Expressions
Public Class SampleClass
Public Function AddIntegers(ByVal arg1 As Integer, ByVal arg2 As Integer) As Integer
Return (arg1 + arg2)
End Function
End Class
Public Shared Sub TestCall()
' This expression represents a call to an instance method that has two arguments.
' The first argument is an expression that creates a new object of the specified type.
Dim callExpr As Expression = Expression.Call(
Expression.[New](GetType(SampleClass)),
GetType(SampleClass).GetMethod("AddIntegers", New Type() {GetType(Integer), GetType(Integer)}),
Expression.Constant(1),
Expression.Constant(2)
)
' Print the expression.
Console.WriteLine(callExpr.ToString())
' The following statement first creates an expression tree,
' then compiles it, and then executes it.
Console.WriteLine(Expression.Lambda(Of Func(Of Integer))(callExpr).Compile()())
End Sub
' This code example produces the following output:
'
' new SampleClass().AddIntegers(1, 2)
' 3
適用対象
Call(MethodInfo, Expression, Expression, Expression, Expression)
4 つの引数を受け取る静的メソッドの呼び出しを表す MethodCallExpression を作成します。
public:
static System::Linq::Expressions::MethodCallExpression ^ Call(System::Reflection::MethodInfo ^ method, System::Linq::Expressions::Expression ^ arg0, System::Linq::Expressions::Expression ^ arg1, System::Linq::Expressions::Expression ^ arg2, System::Linq::Expressions::Expression ^ arg3);
public static System.Linq.Expressions.MethodCallExpression Call(System.Reflection.MethodInfo method, System.Linq.Expressions.Expression arg0, System.Linq.Expressions.Expression arg1, System.Linq.Expressions.Expression arg2, System.Linq.Expressions.Expression arg3);
static member Call : System.Reflection.MethodInfo * System.Linq.Expressions.Expression * System.Linq.Expressions.Expression * System.Linq.Expressions.Expression * System.Linq.Expressions.Expression -> System.Linq.Expressions.MethodCallExpression
Public Shared Function Call (method As MethodInfo, arg0 As Expression, arg1 As Expression, arg2 As Expression, arg3 As Expression) As MethodCallExpression
パラメーター
- method
- MethodInfo
MethodInfo プロパティを等しく設定するMethod。
- arg0
- Expression
最初の引数を表す Expression 。
- arg1
- Expression
2 番目の引数を表す Expression 。
- arg2
- Expression
3 番目の引数を表す Expression 。
- arg3
- Expression
4 番目の引数を表す Expression 。
返品
MethodCallExpression プロパティが NodeType と等しく、CallプロパティとObjectプロパティが指定した値に設定されているMethod。
例外
method が null です。
適用対象
Call(Expression, MethodInfo, Expression[])
引数を受け取るメソッドの呼び出しを表す MethodCallExpression を作成します。
public:
static System::Linq::Expressions::MethodCallExpression ^ Call(System::Linq::Expressions::Expression ^ instance, System::Reflection::MethodInfo ^ method, ... cli::array <System::Linq::Expressions::Expression ^> ^ arguments);
public static System.Linq.Expressions.MethodCallExpression Call(System.Linq.Expressions.Expression instance, System.Reflection.MethodInfo method, params System.Linq.Expressions.Expression[] arguments);
static member Call : System.Linq.Expressions.Expression * System.Reflection.MethodInfo * System.Linq.Expressions.Expression[] -> System.Linq.Expressions.MethodCallExpression
Public Shared Function Call (instance As Expression, method As MethodInfo, ParamArray arguments As Expression()) As MethodCallExpression
パラメーター
- instance
- Expression
インスタンス メソッド呼び出しのインスタンスを指定するExpression (null (Visual Basic のstatic) メソッドにShared渡します)。
- method
- MethodInfo
MethodInfo プロパティを等しく設定するMethod。
- arguments
- Expression[]
Expression コレクションの設定に使用するArguments オブジェクトの配列。
返品
MethodCallExpressionと等しいNodeType プロパティと、指定した値に設定されたCall、Object、およびMethodプロパティを持つArguments。
例外
method は nullです。
-または-
instance は null であり、 method はインスタンス メソッドを表します。
-または-
arguments は null されず、その要素の 1 つ以上が null。
instance.型は、 methodで表されるメソッドの宣言型に割り当てできません。
-または-
arguments内の要素の数は、methodで表されるメソッドのパラメーターの数と等しくありません。
-または-
argumentsの 1 つ以上の要素は、methodで表されるメソッドの対応するパラメーターに割り当てできません。
注釈
static (Visual Basic のShared) メソッドの呼び出しを表すには、このメソッドを呼び出すときにnull パラメーターのinstanceを渡すか、代わりにCallを呼び出します。
methodがインスタンス メソッドを表す場合、Typeのinstance プロパティは、methodで表されるメソッドの宣言型に割り当て可能である必要があります。
argumentsがnullされていない場合は、methodで表されるメソッドのパラメーターの数と同じ数の要素が必要です。
arguments内の各要素はnullする必要はありません。また、methodんだ後でも、の対応するパラメーターに割り当て可能である必要があります。
Note
要素は、対応するメソッド パラメーターが Expression型の場合にのみ引用符で囲まれます。 引用符は、要素が Quote ノードにラップされていることを意味します。 結果のノードは、UnaryExpression プロパティがOperandの要素であるargumentsです。
ArgumentsがMethodCallExpressionされている場合、結果のargumentsのnullプロパティは空です。 それ以外の場合は、 argumentsと同じ要素が含まれ、その一部は引用符で囲まれる可能性があります。
結果のTypeのMethodCallExpressionプロパティは、methodで表されるメソッドの戻り値の型と等しくなります。
適用対象
Call(Expression, MethodInfo, IEnumerable<Expression>)
引数を受け取るメソッドの呼び出しを表す MethodCallExpression を作成します。
public:
static System::Linq::Expressions::MethodCallExpression ^ Call(System::Linq::Expressions::Expression ^ instance, System::Reflection::MethodInfo ^ method, System::Collections::Generic::IEnumerable<System::Linq::Expressions::Expression ^> ^ arguments);
public static System.Linq.Expressions.MethodCallExpression Call(System.Linq.Expressions.Expression instance, System.Reflection.MethodInfo method, System.Collections.Generic.IEnumerable<System.Linq.Expressions.Expression> arguments);
static member Call : System.Linq.Expressions.Expression * System.Reflection.MethodInfo * seq<System.Linq.Expressions.Expression> -> System.Linq.Expressions.MethodCallExpression
Public Shared Function Call (instance As Expression, method As MethodInfo, arguments As IEnumerable(Of Expression)) As MethodCallExpression
パラメーター
- instance
- Expression
Expression プロパティを (Visual Basic のObject) nullに対してstatic渡す) と同じ値に設定するShared。
- method
- MethodInfo
MethodInfo プロパティを等しく設定するMethod。
- arguments
- IEnumerable<Expression>
IEnumerable<T> コレクションの設定に使用するExpression オブジェクトを含むArguments。
返品
MethodCallExpressionと等しいNodeType プロパティと、指定した値に設定されたCall、Object、およびMethodプロパティを持つArguments。
例外
instance.型は、 methodで表されるメソッドの宣言型に割り当てできません。
-または-
arguments内の要素の数は、methodで表されるメソッドのパラメーターの数と等しくありません。
-または-
argumentsの 1 つ以上の要素は、methodで表されるメソッドの対応するパラメーターに割り当てできません。
注釈
static (Visual Basic のShared) メソッドの呼び出しを表すには、このメソッドを呼び出すときにnull パラメーターのinstanceを渡すか、代わりにCallを呼び出します。
methodがインスタンス メソッドを表す場合、Typeのinstance プロパティは、methodで表されるメソッドの宣言型に割り当て可能である必要があります。
argumentsがnullされていない場合は、methodで表されるメソッドのパラメーターの数と同じ数の要素が必要です。
arguments内の各要素はnullする必要はありません。また、methodんだ後でも、の対応するパラメーターに割り当て可能である必要があります。
Note
要素は、対応するメソッド パラメーターが Expression型の場合にのみ引用符で囲まれます。 引用符は、要素が Quote ノードにラップされていることを意味します。 結果のノードは、UnaryExpression プロパティがOperandの要素であるargumentsです。
ArgumentsがMethodCallExpressionされている場合、結果のargumentsのnullプロパティは空です。 それ以外の場合は、 argumentsと同じ要素が含まれ、その一部は引用符で囲まれる可能性があります。
結果のTypeのMethodCallExpressionプロパティは、methodで表されるメソッドの戻り値の型と等しくなります。
適用対象
Call(MethodInfo, Expression[])
引数を持つMethodCallExpression (Visual Basic のstatic) メソッドの呼び出しを表すSharedを作成します。
public:
static System::Linq::Expressions::MethodCallExpression ^ Call(System::Reflection::MethodInfo ^ method, ... cli::array <System::Linq::Expressions::Expression ^> ^ arguments);
public static System.Linq.Expressions.MethodCallExpression Call(System.Reflection.MethodInfo method, params System.Linq.Expressions.Expression[] arguments);
static member Call : System.Reflection.MethodInfo * System.Linq.Expressions.Expression[] -> System.Linq.Expressions.MethodCallExpression
Public Shared Function Call (method As MethodInfo, ParamArray arguments As Expression()) As MethodCallExpression
パラメーター
- method
- MethodInfo
MethodInfo プロパティを等しく設定するstatic (Visual Basic のShared) メソッドを表すMethod。
- arguments
- Expression[]
Expression コレクションの設定に使用するArguments オブジェクトの配列。
返品
MethodCallExpression プロパティが NodeType と等しく、CallプロパティとMethodプロパティが指定した値に設定されているArguments。
例外
method は nullです。
arguments内の要素の数は、methodで表されるメソッドのパラメーターの数と等しくありません。
-または-
argumentsの 1 つ以上の要素は、methodで表されるメソッドの対応するパラメーターに割り当てできません。
注釈
argumentsがnullされていない場合は、methodで表されるメソッドのパラメーターの数と同じ数の要素が必要です。
arguments内の各要素はnullする必要はありません。また、methodんだ後でも、の対応するパラメーターに割り当て可能である必要があります。
Note
要素は、対応するメソッド パラメーターが Expression型の場合にのみ引用符で囲まれます。 引用符は、要素が Quote ノードにラップされていることを意味します。 結果のノードは、UnaryExpression プロパティがOperandの要素であるargumentsです。
ArgumentsがMethodCallExpressionされている場合、結果のargumentsのnullプロパティは空です。 それ以外の場合は、 argumentsと同じ要素が含まれ、その一部は引用符で囲まれる可能性があります。
結果のTypeのMethodCallExpressionプロパティは、methodで表されるメソッドの戻り値の型と等しくなります。
Object プロパティはnull。
適用対象
Call(MethodInfo, Expression)
1 つの引数を受け取るMethodCallExpression (Visual Basic では static) メソッドの呼び出しを表すSharedを作成します。
public:
static System::Linq::Expressions::MethodCallExpression ^ Call(System::Reflection::MethodInfo ^ method, System::Linq::Expressions::Expression ^ arg0);
public static System.Linq.Expressions.MethodCallExpression Call(System.Reflection.MethodInfo method, System.Linq.Expressions.Expression arg0);
static member Call : System.Reflection.MethodInfo * System.Linq.Expressions.Expression -> System.Linq.Expressions.MethodCallExpression
Public Shared Function Call (method As MethodInfo, arg0 As Expression) As MethodCallExpression
パラメーター
- method
- MethodInfo
MethodInfo プロパティを等しく設定するMethod。
- arg0
- Expression
最初の引数を表す Expression 。
返品
MethodCallExpression プロパティが NodeType と等しく、CallプロパティとObjectプロパティが指定した値に設定されているMethod。
例外
method が null です。
例
次の例では、1 つの引数を受け取る static (Visual Basic のShared ) メソッドを呼び出す式を作成する方法を示します。
// Add the following directive to your file:
// using System.Linq.Expressions;
public class SampleClass
{
public static int Increment(int arg1)
{
return arg1 + 1;
}
}
static public void TestCall()
{
//This expression represents a call to an instance method with one argument.
Expression callExpr = Expression.Call(
typeof(SampleClass).GetMethod("Increment"),
Expression.Constant(2)
);
// Print out the expression.
Console.WriteLine(callExpr.ToString());
// The following statement first creates an expression tree,
// then compiles it, and then executes it.
Console.WriteLine(Expression.Lambda<Func<int>>(callExpr).Compile()());
// This code example produces the following output:
//
// Increment(2)
// 3
}
' Add the following directive to your file:
' Imports System.Linq.Expressions
Public Class SampleClass
Shared Function Increment(ByVal arg1 As Integer) As Integer
Return arg1 + 1
End Function
End Class
Shared Sub TestCall()
'This expression represents a call to an instance method with one argument.
Dim callExpr As Expression = Expression.Call(
GetType(SampleClass).GetMethod("Increment"),
Expression.Constant(2))
' Print the expression.
Console.WriteLine(callExpr.ToString())
' The following statement first creates an expression tree,
' then compiles it, and then executes it.
Console.WriteLine(Expression.Lambda(Of Func(Of Integer))(callExpr).Compile()())
End Sub
' This code example produces the following output:
'
' Increment(2)
' 3
適用対象
Call(MethodInfo, IEnumerable<Expression>)
静的 (Visual Basic では Shared) メソッドの呼び出しを表す MethodCallExpression を作成します。
public:
static System::Linq::Expressions::MethodCallExpression ^ Call(System::Reflection::MethodInfo ^ method, System::Collections::Generic::IEnumerable<System::Linq::Expressions::Expression ^> ^ arguments);
public static System.Linq.Expressions.MethodCallExpression Call(System.Reflection.MethodInfo method, System.Collections.Generic.IEnumerable<System.Linq.Expressions.Expression> arguments);
static member Call : System.Reflection.MethodInfo * seq<System.Linq.Expressions.Expression> -> System.Linq.Expressions.MethodCallExpression
Public Shared Function Call (method As MethodInfo, arguments As IEnumerable(Of Expression)) As MethodCallExpression
パラメーター
- method
- MethodInfo
ターゲット メソッドを表す MethodInfo 。
- arguments
- IEnumerable<Expression>
呼び出し引数を表す Expression のコレクション。
返品
MethodCallExpression プロパティが NodeType と等しく、CallプロパティとObjectプロパティが指定した値に設定されているMethod。
適用対象
Call(Expression, MethodInfo)
引数を受け取たないメソッドの呼び出しを表す MethodCallExpression を作成します。
public:
static System::Linq::Expressions::MethodCallExpression ^ Call(System::Linq::Expressions::Expression ^ instance, System::Reflection::MethodInfo ^ method);
public static System.Linq.Expressions.MethodCallExpression Call(System.Linq.Expressions.Expression instance, System.Reflection.MethodInfo method);
static member Call : System.Linq.Expressions.Expression * System.Reflection.MethodInfo -> System.Linq.Expressions.MethodCallExpression
Public Shared Function Call (instance As Expression, method As MethodInfo) As MethodCallExpression
パラメーター
- instance
- Expression
インスタンス メソッド呼び出しのインスタンスを指定するExpression (null (Visual Basic のstatic) メソッドにShared渡します)。
- method
- MethodInfo
MethodInfo プロパティを等しく設定するMethod。
返品
MethodCallExpression プロパティが NodeType と等しく、CallプロパティとObjectプロパティが指定した値に設定されているMethod。
例外
instance.型は、 methodで表されるメソッドの宣言型に割り当てできません。
例
次のコード例は、引数なしでメソッドを呼び出す式を作成する方法を示しています。
// Add the following directive to your file:
// using System.Linq.Expressions;
// This expression represents a call to an instance method without arguments.
Expression callExpr = Expression.Call(
Expression.Constant("sample string"), typeof(String).GetMethod("ToUpper", new Type[] { }));
// Print out the expression.
Console.WriteLine(callExpr.ToString());
// The following statement first creates an expression tree,
// then compiles it, and then executes it.
Console.WriteLine(Expression.Lambda<Func<String>>(callExpr).Compile()());
// This code example produces the following output:
//
// "sample string".ToUpper
// SAMPLE STRING
' Add the following directive to your file:
' Imports System.Linq.Expressions
' This expression represents a call to an instance method without arguments.
Dim callExpr As Expression = Expression.Call(
Expression.Constant("sample string"), GetType(String).GetMethod("ToUpper", New Type() {}))
' Print the expression.
Console.WriteLine(callExpr.ToString())
' The following statement first creates an expression tree,
' then compiles it, and then executes it.
Console.WriteLine(Expression.Lambda(Of Func(Of String))(callExpr).Compile()())
' This code example produces the following output:
'
' "sample string".ToUpper
' SAMPLE STRING
注釈
static (Visual Basic のShared) メソッドの呼び出しを表すには、このメソッドを呼び出すときに、null パラメーターのinstanceを渡します。
methodがインスタンス メソッドを表す場合、Typeのinstance プロパティは、methodで表されるメソッドの宣言型に割り当て可能である必要があります。
結果のArgumentsのMethodCallExpression プロパティが空です。
Type プロパティは、methodで表されるメソッドの戻り値の型と等しくなります。
適用対象
Call(MethodInfo, Expression, Expression)
2 つの引数を受け取る静的メソッドの呼び出しを表す MethodCallExpression を作成します。
public:
static System::Linq::Expressions::MethodCallExpression ^ Call(System::Reflection::MethodInfo ^ method, System::Linq::Expressions::Expression ^ arg0, System::Linq::Expressions::Expression ^ arg1);
public static System.Linq.Expressions.MethodCallExpression Call(System.Reflection.MethodInfo method, System.Linq.Expressions.Expression arg0, System.Linq.Expressions.Expression arg1);
static member Call : System.Reflection.MethodInfo * System.Linq.Expressions.Expression * System.Linq.Expressions.Expression -> System.Linq.Expressions.MethodCallExpression
Public Shared Function Call (method As MethodInfo, arg0 As Expression, arg1 As Expression) As MethodCallExpression
パラメーター
- method
- MethodInfo
MethodInfo プロパティを等しく設定するMethod。
- arg0
- Expression
最初の引数を表す Expression 。
- arg1
- Expression
2 番目の引数を表す Expression 。
返品
MethodCallExpression プロパティが NodeType と等しく、CallプロパティとObjectプロパティが指定した値に設定されているMethod。
例外
method が null です。