DefineMethod Method (String, MethodAttributes, Type, Type[])

TypeBuilder.DefineMethod Method (String, MethodAttributes, Type, Type[])

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

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

member DefineMethod : 
        name:string * 
        attributes:MethodAttributes * 
        returnType:Type * 
        parameterTypes:Type[] -> MethodBuilder 


Type: System.String
The name of the method. name cannot contain embedded nulls.
Type: System.Reflection.MethodAttributes
The attributes of the method.
Type: System.Type
The return type of the method.
Type: System.Type[]
The types of the parameters of the method.

Return Value

Type: System.Reflection.Emit.MethodBuilder
The defined method.


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 a null reference (Nothing in Visual Basic).


The type was previously created using CreateType.


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

The following code sample demonstrates the use of DefineMethod to set a constructor's particular signature and attributes on a dynamic type and to return a corresponding MethodBuilder for MSIL population.

No code example is currently available or this language may not be supported.

.NET Framework

Supported in: 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Community Additions

© 2015 Microsoft