LogicalMethodInfo.Invoke メソッド
現在の LogicalMethodInfo が表すメソッドを呼び出します。
Public Function Invoke( _
ByVal target As Object, _ ByVal values() As Object _) As Object()
[C#]
public object[] Invoke(objecttarget,object[] values);
[C++]
public: Object* Invoke(Object* target,Object* values __gc[]) __gc[];
[JScript]
public function Invoke(
target : Object,values : Object[]) : Object[];
パラメータ
- target
メソッドの呼び出し元となる Object のインスタンス。 - values
呼び出すメソッドの引数リスト。これは、メソッドのパラメータと同じ数、順序、型のオブジェクトの配列です。メソッドにパラメータが必要ない場合、 values パラメータは null 参照 (Visual Basic では Nothing) です。
戻り値
呼び出されたメソッドの戻り値と out パラメータを表す Object 型の配列。
例外
例外の種類 | 条件 |
---|---|
TargetException | target パラメータが null 参照 (Visual Basic では Nothing) です。 |
ArgumentException | values パラメータの数、型、およびパラメータの順序が、呼び出されたメソッドのシグネチャと一致しません。 |
MemberAccessException | 呼び出し元に、このメソッドを呼び出すためのアクセス許可がありません。 |
TargetInvocationException | 呼び出されたメソッドが例外をスローしました。 |
使用例
Imports System
Imports System.Reflection
Imports System.Web.Services.Protocols
Imports Microsoft.VisualBasic
Public Class MyService
Public Function Add(xValue As Integer, yValue As Integer) As Integer
Return xValue + yValue
End Function 'Add
End Class 'MyService
Public Class LogicalMethodInfo_Constructor
Public Shared Sub Main()
Dim myType As Type = GetType(MyService)
Dim myMethodInfo As MethodInfo = myType.GetMethod("Add")
Dim myLogicalMethodInfo As New LogicalMethodInfo(myMethodInfo)
Console.WriteLine(ControlChars.NewLine + "Printing properties of method : {0}" + _
ControlChars.NewLine, myLogicalMethodInfo.ToString())
Console.WriteLine(ControlChars.NewLine + "The declaring type of the method {0} is :" + _
ControlChars.NewLine, myLogicalMethodInfo.Name)
Console.WriteLine(ControlChars.Tab + myLogicalMethodInfo.DeclaringType.ToString())
Console.WriteLine(ControlChars.NewLine + "The parameters of the method {0} are :" + _
ControlChars.NewLine, myLogicalMethodInfo.Name)
Dim myParameters As ParameterInfo() = myLogicalMethodInfo.Parameters
Dim i As Integer
For i = 0 To myParameters.Length - 1
Console.WriteLine(ControlChars.Tab + myParameters(i).Name + " : " + _
myParameters(i).ParameterType.ToString())
Next i
Console.WriteLine(ControlChars.NewLine + "The return type of the method {0} is :" + _
ControlChars.NewLine, myLogicalMethodInfo.Name)
Console.WriteLine(ControlChars.Tab + myLogicalMethodInfo.ReturnType.ToString())
Dim service As New MyService()
Console.WriteLine(ControlChars.NewLine + "Invoking the method {0}" + _
ControlChars.NewLine, myLogicalMethodInfo.Name)
Console.WriteLine(ControlChars.Tab + "The sum of 10 and 10 is : {0}", _
myLogicalMethodInfo.Invoke(service, New Object() {10, 10}))
End Sub 'Main
End Class 'LogicalMethodInfo_Constructor
[C#]
using System;
using System.Reflection;
using System.Web.Services.Protocols;
public class MyService
{
public int Add(int xValue, int yValue)
{
return (xValue + yValue);
}
}
public class LogicalMethodInfo_Constructor
{
public static void Main()
{
Type myType = typeof(MyService);
MethodInfo myMethodInfo = myType.GetMethod("Add");
LogicalMethodInfo myLogicalMethodInfo =
new LogicalMethodInfo(myMethodInfo);
Console.WriteLine("\nPrinting properties of method : {0}\n",
myLogicalMethodInfo.ToString());
Console.WriteLine("\nThe declaring type of the method {0} is :\n",
myLogicalMethodInfo.Name);
Console.WriteLine("\t" + myLogicalMethodInfo.DeclaringType);
Console.WriteLine("\nThe parameters of the method {0} are :\n",
myLogicalMethodInfo.Name);
ParameterInfo[] myParameters = myLogicalMethodInfo.Parameters;
for(int i = 0; i < myParameters.Length; i++)
{
Console.WriteLine("\t" + myParameters[i].Name +
" : " + myParameters[i].ParameterType);
}
Console.WriteLine("\nThe return type of the method {0} is :\n",
myLogicalMethodInfo.Name);
Console.WriteLine("\t" + myLogicalMethodInfo.ReturnType);
MyService service = new MyService();
Console.WriteLine("\nInvoking the method {0}\n",
myLogicalMethodInfo.Name);
Console.WriteLine("\tThe sum of 10 and 10 is : {0}",
myLogicalMethodInfo.Invoke(service,
new object[] {10, 10}));
}
}
[C++]
#using <mscorlib.dll>
#using <System.Web.Services.dll>
using namespace System;
using namespace System::Reflection;
using namespace System::Web::Services::Protocols;
public __gc class MyService {
public:
int Add(int xValue, int yValue) {
return (xValue + yValue);
}
};
int main() {
Type* myType = __typeof(MyService);
MethodInfo* myMethodInfo = myType->GetMethod(S"Add");
LogicalMethodInfo* myLogicalMethodInfo =
new LogicalMethodInfo(myMethodInfo);
Console::WriteLine(S"\nPrinting properties of method : {0}\n",
myLogicalMethodInfo);
Console::WriteLine(S"\nThe declaring type of the method {0} is :\n",
myLogicalMethodInfo->Name);
Console::WriteLine(S"\t {0}", myLogicalMethodInfo->DeclaringType);
Console::WriteLine(S"\nThe parameters of the method {0} are :\n",
myLogicalMethodInfo->Name);
ParameterInfo* myParameters[] = myLogicalMethodInfo->Parameters;
for (int i = 0; i < myParameters->Length; i++) {
Console::WriteLine(S"\t {0}",String::Concat(myParameters[i]->Name,
S" : ", myParameters[i]->ParameterType));
}
Console::WriteLine(S"\nThe return type of the method {0} is :\n",
myLogicalMethodInfo->Name);
Console::WriteLine(S"\t {0}", myLogicalMethodInfo->ReturnType);
MyService* service = new MyService();
Console::WriteLine(S"\nInvoking the method {0}\n",
myLogicalMethodInfo->Name);
Object * values __gc[] = new Object * [2];
values[0] = __box(10);
values[1] = __box(10);
Console::WriteLine(S"\tThe sum of 10 and 10 is : {0}",
myLogicalMethodInfo->Invoke(service,values));
}
[JScript] JScript のサンプルはありません。Visual Basic、C#、および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン をクリックします。
必要条件
プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ
参照
LogicalMethodInfo クラス | LogicalMethodInfo メンバ | System.Web.Services.Protocols 名前空間