TypeBuilder.DefineMethod Method (String, MethodAttributes, CallingConventions)


Adds a new method to the type, with the specified name, method attributes, and calling convention.

Namespace:   System.Reflection.Emit
Assembly:  mscorlib (in mscorlib.dll)

public MethodBuilder DefineMethod(
	string name,
	MethodAttributes attributes,
	CallingConventions callingConvention


Type: System.String

The name of the method. name cannot contain embedded nulls.

Type: System.Reflection.MethodAttributes

The attributes of the method.

Type: System.Reflection.CallingConventions

The calling convention of the method.

Return Value

Type: System.Reflection.Emit.MethodBuilder

A MethodBuilder representing the newly defined method.

Exception Condition

The length of name is zero.


The type of the parent of this method is an interface and this method is not virtual (Overridable in Visual Basic).


name is null.


The type was previously created using CreateType.


For the current dynamic type, the IsGenericType property is true, but the IsGenericTypeDefinition property is false.

Use this method overload when you do not know the method signature at the time you define the method. For example, the parameter types and return type of a generic method might be specified by the method's generic type parameters, which must be defined after the method has been added to the type. The parameters and return type of the method can be set later using the MethodBuilder.SetSignature method.

.NET Framework
Available since 2.0
Available since 2.0
Return to top