TypeBuilder.DefineMethod メソッド
定義
重要
一部の情報は、リリース前に大きく変更される可能性があるプレリリースされた製品に関するものです。 Microsoft は、ここに記載されている情報について、明示または黙示を問わず、一切保証しません。
型にメソッドを追加します。
オーバーロード
| 名前 | 説明 |
|---|---|
| DefineMethod(String, MethodAttributes) |
指定した名前とメソッド属性を持つ新しいメソッドを型に追加します。 |
| DefineMethod(String, MethodAttributes, CallingConventions) |
指定した名前、メソッド属性、および呼び出し規則を使用して、新しいメソッドを型に追加します。 |
| DefineMethod(String, MethodAttributes, Type, Type[]) |
指定した名前、メソッド属性、およびメソッド シグネチャを使用して、新しいメソッドを型に追加します。 |
| DefineMethod(String, MethodAttributes, CallingConventions, Type, Type[]) |
指定した名前、メソッド属性、呼び出し規則、およびメソッド シグネチャを使用して、新しいメソッドを型に追加します。 |
| DefineMethod(String, MethodAttributes, CallingConventions, Type, Type[], Type[], Type[], Type[][], Type[][]) |
指定した名前、メソッド属性、呼び出し規則、メソッド シグネチャ、およびカスタム修飾子を使用して、新しいメソッドを型に追加します。 |
DefineMethod(String, MethodAttributes)
指定した名前とメソッド属性を持つ新しいメソッドを型に追加します。
public:
System::Reflection::Emit::MethodBuilder ^ DefineMethod(System::String ^ name, System::Reflection::MethodAttributes attributes);
public System.Reflection.Emit.MethodBuilder DefineMethod(string name, System.Reflection.MethodAttributes attributes);
member this.DefineMethod : string * System.Reflection.MethodAttributes -> System.Reflection.Emit.MethodBuilder
Public Function DefineMethod (name As String, attributes As MethodAttributes) As MethodBuilder
パラメーター
- name
- String
メソッドの名前。
name 埋め込み null を含めることはできません。
- attributes
- MethodAttributes
メソッドの属性。
返品
新しく定義されたメソッドを表す MethodBuilder 。
例外
nameの長さは 0 です。
-または-
このメソッドの親の型はインターフェイスであり、このメソッドは仮想ではありません (Visual Basicでは Overridable)。
name は nullです。
この型は、以前に CreateType() を使用して作成されました。
-または-
現在の動的な型の場合、 IsGenericType プロパティは trueされますが、 IsGenericTypeDefinition プロパティは false。
例
次のコード例では、パラメーター型と戻り値の型がジェネリック型パラメーターで指定 DemoMethod という名前のジェネリック メソッドを定義します。 このメソッドは、標準の呼び出し規則を使用して、シグネチャなしで定義されます。
MethodBuilder.DefineGenericParametersメソッドを使用してDemoMethodジェネリック メソッドを作成し、新しく定義された型パラメーターをシグネチャと戻り値の型に使用します。
このコード例は、 DefineGenericParameters メソッドで提供されるより大きな例の一部です。
// Define a Shared, Public method with standard calling
// conventions. Do not specify the parameter types or the
// return type, because type parameters will be used for
// those types, and the type parameters have not been
// defined yet.
MethodBuilder demoMethod = demoType.DefineMethod(
"DemoMethod",
MethodAttributes.Public | MethodAttributes.Static
);
' Define a Shared, Public method with standard calling
' conventions. Do not specify the parameter types or the
' return type, because type parameters will be used for
' those types, and the type parameters have not been
' defined yet.
Dim demoMethod As MethodBuilder = _
demoType.DefineMethod("DemoMethod", _
MethodAttributes.Public Or MethodAttributes.Static)
// Defining generic parameters for the method makes it a
// generic method. By convention, type parameters are
// single alphabetic characters. T and U are used here.
//
string[] typeParamNames = {"T", "U"};
GenericTypeParameterBuilder[] typeParameters =
demoMethod.DefineGenericParameters(typeParamNames);
// The second type parameter is constrained to be a
// reference type.
typeParameters[1].SetGenericParameterAttributes(
GenericParameterAttributes.ReferenceTypeConstraint);
' Defining generic parameters for the method makes it a
' generic method. By convention, type parameters are
' single alphabetic characters. T and U are used here.
'
Dim typeParamNames() As String = {"T", "U"}
Dim typeParameters() As GenericTypeParameterBuilder = _
demoMethod.DefineGenericParameters(typeParamNames)
' The second type parameter is constrained to be a
' reference type.
typeParameters(1).SetGenericParameterAttributes( _
GenericParameterAttributes.ReferenceTypeConstraint)
// Set parameter types for the method. The method takes
// one parameter, and its type is specified by the first
// type parameter, T.
Type[] parms = {typeParameters[0]};
demoMethod.SetParameters(parms);
// Set the return type for the method. The return type is
// specified by the second type parameter, U.
demoMethod.SetReturnType(typeParameters[1]);
' Set parameter types for the method. The method takes
' one parameter, and its type is specified by the first
' type parameter, T.
Dim params() As Type = {typeParameters(0)}
demoMethod.SetParameters(params)
' Set the return type for the method. The return type is
' specified by the second type parameter, U.
demoMethod.SetReturnType(typeParameters(1))
注釈
メソッド定義時にメソッド シグネチャがわからない場合は、このメソッド オーバーロードを使用します。 たとえば、ジェネリック メソッドのパラメーター型と戻り値の型は、メソッドのジェネリック型パラメーターで指定できます。これは、メソッドが型に追加された後に定義する必要があります。 メソッドのパラメーターと戻り値の型は、後で MethodBuilder.SetSignature メソッドを使用して設定できます。
このメソッド オーバーロードは、 CallingConventions.Standardを使用してメソッドを定義します。 シグネチャのないメソッドを定義する必要がある場合は、別の呼び出し規則を使用して、 DefineMethod(String, MethodAttributes, CallingConventions) メソッドのオーバーロードを使用します。
こちらもご覧ください
適用対象
DefineMethod(String, MethodAttributes, CallingConventions)
指定した名前、メソッド属性、および呼び出し規則を使用して、新しいメソッドを型に追加します。
public:
System::Reflection::Emit::MethodBuilder ^ DefineMethod(System::String ^ name, System::Reflection::MethodAttributes attributes, System::Reflection::CallingConventions callingConvention);
public System.Reflection.Emit.MethodBuilder DefineMethod(string name, System.Reflection.MethodAttributes attributes, System.Reflection.CallingConventions callingConvention);
member this.DefineMethod : string * System.Reflection.MethodAttributes * System.Reflection.CallingConventions -> System.Reflection.Emit.MethodBuilder
Public Function DefineMethod (name As String, attributes As MethodAttributes, callingConvention As CallingConventions) As MethodBuilder
パラメーター
- name
- String
メソッドの名前。
name 埋め込み null を含めることはできません。
- attributes
- MethodAttributes
メソッドの属性。
- callingConvention
- CallingConventions
メソッドの呼び出し規約。
返品
新しく定義されたメソッドを表す MethodBuilder 。
例外
nameの長さは 0 です。
-または-
このメソッドの親の型はインターフェイスであり、このメソッドは仮想ではありません (Overridable in Visual Basic)。
name は nullです。
この型は、以前に CreateType() を使用して作成されました。
-または-
現在の動的な型の場合、 IsGenericType プロパティは trueされますが、 IsGenericTypeDefinition プロパティは false。
注釈
メソッド定義時にメソッド シグネチャがわからない場合は、このメソッド オーバーロードを使用します。 たとえば、ジェネリック メソッドのパラメーター型と戻り値の型は、メソッドのジェネリック型パラメーターで指定できます。これは、メソッドが型に追加された後に定義する必要があります。 メソッドのパラメーターと戻り値の型は、後で MethodBuilder.SetSignature メソッドを使用して設定できます。
こちらもご覧ください
適用対象
DefineMethod(String, MethodAttributes, Type, Type[])
指定した名前、メソッド属性、およびメソッド シグネチャを使用して、新しいメソッドを型に追加します。
public:
System::Reflection::Emit::MethodBuilder ^ DefineMethod(System::String ^ name, System::Reflection::MethodAttributes attributes, Type ^ returnType, cli::array <Type ^> ^ parameterTypes);
public System.Reflection.Emit.MethodBuilder DefineMethod(string name, System.Reflection.MethodAttributes attributes, Type returnType, Type[] parameterTypes);
member this.DefineMethod : string * System.Reflection.MethodAttributes * Type * Type[] -> System.Reflection.Emit.MethodBuilder
Public Function DefineMethod (name As String, attributes As MethodAttributes, returnType As Type, parameterTypes As Type()) As MethodBuilder
パラメーター
- name
- String
メソッドの名前。
name 埋め込み null を含めることはできません。
- attributes
- MethodAttributes
メソッドの属性。
- returnType
- Type
メソッドの戻り値の型。
- parameterTypes
- Type[]
メソッドのパラメーターの型。
返品
定義されたメソッド。
例外
nameの長さは 0 です。
-または-
このメソッドの親の型はインターフェイスであり、このメソッドは仮想ではありません (Visual Basicでは Overridable)。
name は nullです。
この型は、以前に CreateType() を使用して作成されました。
-または-
現在の動的な型の場合、 IsGenericType プロパティは trueされますが、 IsGenericTypeDefinition プロパティは false。
例
次のコード サンプルでは、 DefineMethod を使用して、コンストラクターの特定のシグネチャと属性を動的な型に設定し、MSIL の作成に対応する MethodBuilder を返す方法を示します。
using System;
using System.Threading;
using System.Reflection;
using System.Reflection.Emit;
using System.Security.Permissions;
public interface IMyInterface
{
String HelloMethod(String parameter);
}
public class Example
{
public static void Main()
{
Type myNestedClassType = CreateCallee(Thread.GetDomain());
// Cretae an instance of 'MyNestedClass'.
IMyInterface myInterface =
(IMyInterface)Activator.CreateInstance(myNestedClassType);
Console.WriteLine(myInterface.HelloMethod("Bill"));
}
// Create the callee transient dynamic assembly.
private static Type CreateCallee(AppDomain myAppDomain)
{
AssemblyName myAssemblyName = new AssemblyName();
myAssemblyName.Name = "Example";
// Create the callee dynamic assembly.
AssemblyBuilder myAssembly =
myAppDomain.DefineDynamicAssembly(myAssemblyName, AssemblyBuilderAccess.Run);
// Create a dynamic module in the callee assembly.
ModuleBuilder myModule = myAssembly.DefineDynamicModule("EmittedModule");
// Define a public class named "MyHelloWorld".
TypeBuilder myHelloWorldType =
myModule.DefineType("MyHelloWorld", TypeAttributes.Public);
// Define a public nested class named 'MyNestedClass'.
TypeBuilder myNestedClassType =
myHelloWorldType.DefineNestedType("MyNestedClass",
TypeAttributes.NestedPublic, typeof(Example),
new Type[]{typeof(IMyInterface)});
// Implement 'IMyInterface' interface.
myNestedClassType.AddInterfaceImplementation(typeof(IMyInterface));
// Define 'HelloMethod' of 'IMyInterface'.
MethodBuilder myHelloMethod =
myNestedClassType.DefineMethod("HelloMethod",
MethodAttributes.Public | MethodAttributes.Virtual,
typeof(String), new Type[]{typeof(String)});
// Generate IL for 'GetGreeting' method.
ILGenerator myMethodIL = myHelloMethod.GetILGenerator();
myMethodIL.Emit(OpCodes.Ldstr, "Hi! ");
myMethodIL.Emit(OpCodes.Ldarg_1);
MethodInfo infoMethod =
typeof(String).GetMethod("Concat",new Type[]{typeof(string),typeof(string)});
myMethodIL.Emit(OpCodes.Call, infoMethod);
myMethodIL.Emit(OpCodes.Ret);
MethodInfo myHelloMethodInfo =
typeof(IMyInterface).GetMethod("HelloMethod");
// Implement 'HelloMethod' of 'IMyInterface'.
myNestedClassType.DefineMethodOverride(myHelloMethod, myHelloMethodInfo);
// Create 'MyHelloWorld' type.
Type myType = myHelloWorldType.CreateType();
// Create 'MyNestedClass' type.
return myNestedClassType.CreateType();
}
}
Imports System.Threading
Imports System.Reflection
Imports System.Reflection.Emit
Imports System.Security.Permissions
Public Interface IMyInterface
Function HelloMethod(parameter As String) As String
End Interface 'IMyInterface
Public Class Example
<PermissionSetAttribute(SecurityAction.Demand, Name:="FullTrust")> _
Public Shared Sub Main()
Dim myNestedClassType As Type = CreateCallee(Thread.GetDomain())
' Create an instance of 'MyNestedClass'.
Dim myInterface As IMyInterface = _
CType(Activator.CreateInstance(myNestedClassType), IMyInterface)
Console.WriteLine(myInterface.HelloMethod("Bill"))
End Sub
' Create the callee transient dynamic assembly.
Private Shared Function CreateCallee(myAppDomain As AppDomain) As Type
Dim myAssemblyName As New AssemblyName()
myAssemblyName.Name = "Example"
' Create the callee dynamic assembly.
Dim myAssembly As AssemblyBuilder = _
myAppDomain.DefineDynamicAssembly(myAssemblyName, AssemblyBuilderAccess.Run)
' Create a dynamic module in the callee assembly.
Dim myModule As ModuleBuilder = myAssembly.DefineDynamicModule("EmittedModule")
' Define a public class named "MyHelloWorld".
Dim myHelloWorldType As TypeBuilder = _
myModule.DefineType("MyHelloWorld", TypeAttributes.Public)
' Define a public nested class named 'MyNestedClass'.
Dim myNestedClassType As TypeBuilder = _
myHelloWorldType.DefineNestedType("MyNestedClass", TypeAttributes.NestedPublic, _
GetType(Example), New Type() {GetType(IMyInterface)})
' Implement 'IMyInterface' interface.
myNestedClassType.AddInterfaceImplementation(GetType(IMyInterface))
' Define 'HelloMethod' of 'IMyInterface'.
Dim myHelloMethod As MethodBuilder = _
myNestedClassType.DefineMethod("HelloMethod", MethodAttributes.Public Or _
MethodAttributes.Virtual, GetType(String), New Type() {GetType(String)})
' Generate IL for 'GetGreeting' method.
Dim myMethodIL As ILGenerator = myHelloMethod.GetILGenerator()
myMethodIL.Emit(OpCodes.Ldstr, "Hi! ")
myMethodIL.Emit(OpCodes.Ldarg_1)
Dim infoMethod As MethodInfo = _
GetType(String).GetMethod("Concat", New Type() {GetType(String), GetType(String)})
myMethodIL.Emit(OpCodes.Call, infoMethod)
myMethodIL.Emit(OpCodes.Ret)
Dim myHelloMethodInfo As MethodInfo = GetType(IMyInterface).GetMethod("HelloMethod")
' Implement 'HelloMethod' of 'IMyInterface'.
myNestedClassType.DefineMethodOverride(myHelloMethod, myHelloMethodInfo)
' Create 'MyHelloWorld' type.
Dim myType As Type = myHelloWorldType.CreateType()
' Create 'MyNestedClass' type.
Return myNestedClassType.CreateType()
End Function 'CreateCallee
End Class
適用対象
DefineMethod(String, MethodAttributes, CallingConventions, Type, Type[])
指定した名前、メソッド属性、呼び出し規則、およびメソッド シグネチャを使用して、新しいメソッドを型に追加します。
public:
System::Reflection::Emit::MethodBuilder ^ DefineMethod(System::String ^ name, System::Reflection::MethodAttributes attributes, System::Reflection::CallingConventions callingConvention, Type ^ returnType, cli::array <Type ^> ^ parameterTypes);
public System.Reflection.Emit.MethodBuilder DefineMethod(string name, System.Reflection.MethodAttributes attributes, System.Reflection.CallingConventions callingConvention, Type returnType, Type[] parameterTypes);
member this.DefineMethod : string * System.Reflection.MethodAttributes * System.Reflection.CallingConventions * Type * Type[] -> System.Reflection.Emit.MethodBuilder
Public Function DefineMethod (name As String, attributes As MethodAttributes, callingConvention As CallingConventions, returnType As Type, parameterTypes As Type()) As MethodBuilder
パラメーター
- name
- String
メソッドの名前。
name 埋め込み null を含めることはできません。
- attributes
- MethodAttributes
メソッドの属性。
- callingConvention
- CallingConventions
メソッドの呼び出し規約。
- returnType
- Type
メソッドの戻り値の型。
- parameterTypes
- Type[]
メソッドのパラメーターの型。
返品
新しく定義されたメソッドを表す MethodBuilder 。
例外
nameの長さは 0 です。
-または-
このメソッドの親の型はインターフェイスであり、このメソッドは仮想ではありません (Visual Basicでは Overridable)。
name は nullです。
この型は、以前に CreateType() を使用して作成されました。
-または-
現在の動的な型の場合、 IsGenericType プロパティは trueされますが、 IsGenericTypeDefinition プロパティは false。
例
次のコード サンプルでは、 DefineMethod を使用して、コンストラクターの特定のシグネチャと属性を動的な型に設定し、MSIL の作成に対応する MethodBuilder を返す方法を示します。
using System;
using System.Threading;
using System.Reflection;
using System.Reflection.Emit;
using System.Security.Permissions;
public interface IMyInterface
{
String HelloMethod(String parameter);
}
public class Example
{
public static void Main()
{
Type myNestedClassType = CreateCallee(Thread.GetDomain());
// Cretae an instance of 'MyNestedClass'.
IMyInterface myInterface =
(IMyInterface)Activator.CreateInstance(myNestedClassType);
Console.WriteLine(myInterface.HelloMethod("Bill"));
}
// Create the callee transient dynamic assembly.
private static Type CreateCallee(AppDomain myAppDomain)
{
AssemblyName myAssemblyName = new AssemblyName();
myAssemblyName.Name = "Example";
// Create the callee dynamic assembly.
AssemblyBuilder myAssembly =
myAppDomain.DefineDynamicAssembly(myAssemblyName, AssemblyBuilderAccess.Run);
// Create a dynamic module in the callee assembly.
ModuleBuilder myModule = myAssembly.DefineDynamicModule("EmittedModule");
// Define a public class named "MyHelloWorld".
TypeBuilder myHelloWorldType =
myModule.DefineType("MyHelloWorld", TypeAttributes.Public);
// Define a public nested class named 'MyNestedClass'.
TypeBuilder myNestedClassType =
myHelloWorldType.DefineNestedType("MyNestedClass",
TypeAttributes.NestedPublic, typeof(Example),
new Type[]{typeof(IMyInterface)});
// Implement 'IMyInterface' interface.
myNestedClassType.AddInterfaceImplementation(typeof(IMyInterface));
// Define 'HelloMethod' of 'IMyInterface'.
MethodBuilder myHelloMethod =
myNestedClassType.DefineMethod("HelloMethod",
MethodAttributes.Public | MethodAttributes.Virtual,
typeof(String), new Type[]{typeof(String)});
// Generate IL for 'GetGreeting' method.
ILGenerator myMethodIL = myHelloMethod.GetILGenerator();
myMethodIL.Emit(OpCodes.Ldstr, "Hi! ");
myMethodIL.Emit(OpCodes.Ldarg_1);
MethodInfo infoMethod =
typeof(String).GetMethod("Concat",new Type[]{typeof(string),typeof(string)});
myMethodIL.Emit(OpCodes.Call, infoMethod);
myMethodIL.Emit(OpCodes.Ret);
MethodInfo myHelloMethodInfo =
typeof(IMyInterface).GetMethod("HelloMethod");
// Implement 'HelloMethod' of 'IMyInterface'.
myNestedClassType.DefineMethodOverride(myHelloMethod, myHelloMethodInfo);
// Create 'MyHelloWorld' type.
Type myType = myHelloWorldType.CreateType();
// Create 'MyNestedClass' type.
return myNestedClassType.CreateType();
}
}
Imports System.Threading
Imports System.Reflection
Imports System.Reflection.Emit
Imports System.Security.Permissions
Public Interface IMyInterface
Function HelloMethod(parameter As String) As String
End Interface 'IMyInterface
Public Class Example
<PermissionSetAttribute(SecurityAction.Demand, Name:="FullTrust")> _
Public Shared Sub Main()
Dim myNestedClassType As Type = CreateCallee(Thread.GetDomain())
' Create an instance of 'MyNestedClass'.
Dim myInterface As IMyInterface = _
CType(Activator.CreateInstance(myNestedClassType), IMyInterface)
Console.WriteLine(myInterface.HelloMethod("Bill"))
End Sub
' Create the callee transient dynamic assembly.
Private Shared Function CreateCallee(myAppDomain As AppDomain) As Type
Dim myAssemblyName As New AssemblyName()
myAssemblyName.Name = "Example"
' Create the callee dynamic assembly.
Dim myAssembly As AssemblyBuilder = _
myAppDomain.DefineDynamicAssembly(myAssemblyName, AssemblyBuilderAccess.Run)
' Create a dynamic module in the callee assembly.
Dim myModule As ModuleBuilder = myAssembly.DefineDynamicModule("EmittedModule")
' Define a public class named "MyHelloWorld".
Dim myHelloWorldType As TypeBuilder = _
myModule.DefineType("MyHelloWorld", TypeAttributes.Public)
' Define a public nested class named 'MyNestedClass'.
Dim myNestedClassType As TypeBuilder = _
myHelloWorldType.DefineNestedType("MyNestedClass", TypeAttributes.NestedPublic, _
GetType(Example), New Type() {GetType(IMyInterface)})
' Implement 'IMyInterface' interface.
myNestedClassType.AddInterfaceImplementation(GetType(IMyInterface))
' Define 'HelloMethod' of 'IMyInterface'.
Dim myHelloMethod As MethodBuilder = _
myNestedClassType.DefineMethod("HelloMethod", MethodAttributes.Public Or _
MethodAttributes.Virtual, GetType(String), New Type() {GetType(String)})
' Generate IL for 'GetGreeting' method.
Dim myMethodIL As ILGenerator = myHelloMethod.GetILGenerator()
myMethodIL.Emit(OpCodes.Ldstr, "Hi! ")
myMethodIL.Emit(OpCodes.Ldarg_1)
Dim infoMethod As MethodInfo = _
GetType(String).GetMethod("Concat", New Type() {GetType(String), GetType(String)})
myMethodIL.Emit(OpCodes.Call, infoMethod)
myMethodIL.Emit(OpCodes.Ret)
Dim myHelloMethodInfo As MethodInfo = GetType(IMyInterface).GetMethod("HelloMethod")
' Implement 'HelloMethod' of 'IMyInterface'.
myNestedClassType.DefineMethodOverride(myHelloMethod, myHelloMethodInfo)
' Create 'MyHelloWorld' type.
Dim myType As Type = myHelloWorldType.CreateType()
' Create 'MyNestedClass' type.
Return myNestedClassType.CreateType()
End Function 'CreateCallee
End Class
適用対象
DefineMethod(String, MethodAttributes, CallingConventions, Type, Type[], Type[], Type[], Type[][], Type[][])
指定した名前、メソッド属性、呼び出し規則、メソッド シグネチャ、およびカスタム修飾子を使用して、新しいメソッドを型に追加します。
public:
System::Reflection::Emit::MethodBuilder ^ DefineMethod(System::String ^ name, System::Reflection::MethodAttributes attributes, System::Reflection::CallingConventions callingConvention, Type ^ returnType, cli::array <Type ^> ^ returnTypeRequiredCustomModifiers, cli::array <Type ^> ^ returnTypeOptionalCustomModifiers, cli::array <Type ^> ^ parameterTypes, cli::array <cli::array <Type ^> ^> ^ parameterTypeRequiredCustomModifiers, cli::array <cli::array <Type ^> ^> ^ parameterTypeOptionalCustomModifiers);
public System.Reflection.Emit.MethodBuilder DefineMethod(string name, System.Reflection.MethodAttributes attributes, System.Reflection.CallingConventions callingConvention, Type returnType, Type[] returnTypeRequiredCustomModifiers, Type[] returnTypeOptionalCustomModifiers, Type[] parameterTypes, Type[][] parameterTypeRequiredCustomModifiers, Type[][] parameterTypeOptionalCustomModifiers);
member this.DefineMethod : string * System.Reflection.MethodAttributes * System.Reflection.CallingConventions * Type * Type[] * Type[] * Type[] * Type[][] * Type[][] -> System.Reflection.Emit.MethodBuilder
Public Function DefineMethod (name As String, attributes As MethodAttributes, callingConvention As CallingConventions, returnType As Type, returnTypeRequiredCustomModifiers As Type(), returnTypeOptionalCustomModifiers As Type(), parameterTypes As Type(), parameterTypeRequiredCustomModifiers As Type()(), parameterTypeOptionalCustomModifiers As Type()()) As MethodBuilder
パラメーター
- name
- String
メソッドの名前。
name 埋め込み null を含めることはできません。
- attributes
- MethodAttributes
メソッドの属性。
- callingConvention
- CallingConventions
メソッドの呼び出し規約。
- returnType
- Type
メソッドの戻り値の型。
- returnTypeRequiredCustomModifiers
- Type[]
メソッドの戻り値の型に必要なカスタム修飾子 ( IsConst など) を表す型の配列。 戻り値の型に必要なカスタム修飾子がない場合は、 nullを指定します。
- returnTypeOptionalCustomModifiers
- Type[]
メソッドの戻り値の型の省略可能なカスタム修飾子 ( IsConstなど) を表す型の配列。 戻り値の型に省略可能なカスタム修飾子がない場合は、 nullを指定します。
- parameterTypes
- Type[]
メソッドのパラメーターの型。
- parameterTypeRequiredCustomModifiers
- Type[][]
型の配列の配列。 型の各配列は、 IsConstなど、対応するパラメーターに必要なカスタム修飾子を表します。 特定のパラメーターに必要なカスタム修飾子がない場合は、型の配列の代わりに null を指定します。 どのパラメーターにも必要なカスタム修飾子がない場合は、配列の配列の代わりに null を指定します。
- parameterTypeOptionalCustomModifiers
- Type[][]
型の配列の配列。 型の各配列は、 IsConstなど、対応するパラメーターの省略可能なカスタム修飾子を表します。 特定のパラメーターに省略可能なカスタム修飾子がない場合は、型の配列の代わりに null を指定します。 省略可能なカスタム修飾子を持つパラメーターがない場合は、配列の配列の代わりに null を指定します。
返品
新しく追加されたメソッドを表す MethodBuilder オブジェクト。
例外
nameの長さは 0 です。
-または-
このメソッドの親の型はインターフェイスであり、このメソッドは仮想ではありません (Visual Basicでは Overridable)。
-または-
parameterTypeRequiredCustomModifiersまたはparameterTypeOptionalCustomModifiersのサイズがparameterTypesのサイズと等しくありません。
name は nullです。
この型は、以前に CreateType() を使用して作成されました。
-または-
現在の動的な型の場合、 IsGenericType プロパティは trueされますが、 IsGenericTypeDefinition プロパティは false。
注釈
カスタム修飾子を指定する必要がある場合は、このオーバーロードを使用します。 たとえば、ジェネリック型パラメーターでパラメーター型が指定されているジェネリック メソッドと同様に、メソッドの作成後にカスタム修飾子を指定する必要がある場合は、 DefineMethod(String, MethodAttributes) または DefineMethod(String, MethodAttributes, CallingConventions) メソッドオーバーロードを使用してメソッドを定義し、 MethodBuilder.SetSignature メソッドを使用してカスタム修飾子を使用してパラメーターと戻り値の型を定義できます。
Note
カスタム修飾子の詳細については、「ECMA C# と共通言語インフラストラクチャ標準」および「Standard ECMA-335 - 共通言語インフラストラクチャ (CLI)」を参照してください。