MethodBuilder.SetReturnType Method (Type)

 

Sets the return type of the method.

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

member SetReturnType : 
        returnType:Type -> unit

Parameters

returnType
Type: System.Type

A Type object that represents the return type of the method.

Exception Condition
InvalidOperationException

The current method is generic, but is not a generic method definition. That is, the IsGenericMethod property is true, but the IsGenericMethodDefinition property is false.

Use this method to set the return type of a generic method, when the return type is specified by one of the generic type parameters of the method. If the return type has optional or required custom modifiers, such as IsConst, use the SetSignature(Type, Type[], Type[], Type[], Type[][], Type[][]) method overload.

Calling this method replaces a return type established using the TypeBuilder.DefineMethod method.

The following code example uses the DefineGenericParameters method to make a method generic. The SetParameters method is used to give the method one parameter, whose type will be specified by the first generic type parameter. The SetReturnType method is used to give the method a return type, specified by the second generic type parameter.

This code is part of a larger example provided for the DefineGenericParameters method.

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

.NET Framework
Available since 2.0
Silverlight
Available since 2.0
Return to top
Show: