Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All

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

Note: This method is new in the .NET Framework version 2.0.

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

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

public MethodBuilder DefineMethod (
	string name,
	MethodAttributes attributes,
	CallingConventions callingConvention,
	Type returnType,
	Type[] returnTypeRequiredCustomModifiers,
	Type[] returnTypeOptionalCustomModifiers,
	Type[] parameterTypes,
	Type[][] parameterTypeRequiredCustomModifiers,
	Type[][] parameterTypeOptionalCustomModifiers
)
public MethodBuilder DefineMethod (
	String name, 
	MethodAttributes attributes, 
	CallingConventions callingConvention, 
	Type returnType, 
	Type[] returnTypeRequiredCustomModifiers, 
	Type[] returnTypeOptionalCustomModifiers, 
	Type[] parameterTypes, 
	Type[][] parameterTypeRequiredCustomModifiers, 
	Type[][] parameterTypeOptionalCustomModifiers
)
public function DefineMethod (
	name : String, 
	attributes : MethodAttributes, 
	callingConvention : CallingConventions, 
	returnType : Type, 
	returnTypeRequiredCustomModifiers : Type[], 
	returnTypeOptionalCustomModifiers : Type[], 
	parameterTypes : Type[], 
	parameterTypeRequiredCustomModifiers : Type[][], 
	parameterTypeOptionalCustomModifiers : Type[][]
) : MethodBuilder

Parameters

name

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

attributes

The attributes of the method.

callingConvention

The calling convention of the method.

returnType

The return type of the method.

returnTypeRequiredCustomModifiers

An array of types representing the required custom modifiers, such as IsConst, for the return type of the method. If the return type has no required custom modifiers, specify a null reference (Nothing in Visual Basic).

returnTypeOptionalCustomModifiers

An array of types representing the optional custom modifiers, such as IsConst, for the return type of the method. If the return type has no required custom modifiers, specify a null reference (Nothing in Visual Basic).

parameterTypes

The types of the parameters of the method.

parameterTypeRequiredCustomModifiers

An array of arrays of types. Each array of types represents the required custom modifiers for the corresponding parameter, such as IsConst. If a particular parameter has no required custom modifiers, specify a null reference (Nothing in Visual Basic) instead of an array of types. If none of the parameters have required custom modifiers, specify a null reference (Nothing in Visual Basic) instead of an array of arrays.

parameterTypeOptionalCustomModifiers

An array of arrays of types. Each array of types represents the optional custom modifiers for the corresponding parameter, such as IsConst. If a particular parameter has no optional custom modifiers, specify a null reference (Nothing in Visual Basic) instead of an array of types. If none of the parameters have optional custom modifiers, specify a null reference (Nothing in Visual Basic) instead of an array of arrays.

Return Value

A MethodBuilder object representing the newly added method.

Exception typeCondition

ArgumentException

The length of name is zero.

-or-

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

-or-

The size of parameterTypeRequiredCustomModifiers or parameterTypeOptionalCustomModifiers does not equal the size of parameterTypes.

ArgumentNullException

name is a null reference (Nothing in Visual Basic).

InvalidOperationException

The type was previously created using CreateType.

-or-

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

Use this overload if you need to specify custom modifiers. If you need to specify custom modifiers after the method has been created, as for example with a generic method whose parameter types are specified by its generic type parameters, you can use the DefineMethod(String,MethodAttributes) or DefineMethod(String,MethodAttributes,CallingConventions) method overloads to define the method and then use the MethodBuilder.SetSignature method to define the parameter and return types with custom modifiers.

NoteNote

For more information on custom modifiers, see the ECMA Partition II Metadata documentation. Partition II documentation is available online at http://msdn.microsoft.com/net/ecma/ and http://www.ecma-international.org/publications/standards/Ecma-335.htm.

Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

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

.NET Framework

Supported in: 2.0

Community Additions

ADD
Show:
© 2015 Microsoft