Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

GenericTypeParameterBuilder.MakeByRefType Method

Returns a Type object that represents the current generic type parameter when passed as a reference parameter.

Namespace:  System.Reflection.Emit
Assembly:  mscorlib (in mscorlib.dll)
public override Type MakeByRefType()

Return Value

Type: System.Type
A Type object that represents the current generic type parameter when passed as a reference parameter.

The MakeByRefType method provides a way to generate ref types (ByRef in Visual Basic) for parameter lists.

The following code example creates a dynamic module, an abstract generic type named Sample with one type parameter, T, and an abstract method named TestMethod. TestMethod takes a ref parameter (ByRef in Visual Basic) of type T, a pointer to type T, and an array of T. This method returns a two-dimensional array of T.

// Define a dynamic assembly to contain the sample type. 
AppDomain myDomain = AppDomain.CurrentDomain;
AssemblyName myAsmName = new
AssemblyBuilder myAssembly = myDomain.DefineDynamicAssembly(
    myAsmName, AssemblyBuilderAccess.Run);
ModuleBuilder myModule = myAssembly.DefineDynamicModule(

// Define the sample type.
TypeBuilder myType = myModule.DefineType("Sample",
    TypeAttributes.Public | TypeAttributes.Abstract);

// Make the sample type a generic type, by defining a type
// parameter T. All type parameters are defined at the same
// time, by passing an array containing the type parameter
// names. 
string[] typeParamNames = { "T" };
GenericTypeParameterBuilder[] typeParams =

// Define a method that takes a ByRef argument of type T, a
// pointer to type T, and one-dimensional array of type T. The
// method returns a two-dimensional array of type T.
// To create this method, you need Type objects that represent the
// parameter types and the return type. Use the MakeByRefType, 
// MakePointerType, and MakeArrayType methods to create the Type
// objects, using the generic type parameter T.
Type byRefType = typeParams[0].MakeByRefType();
Type pointerType = typeParams[0].MakePointerType();
Type arrayType = typeParams[0].MakeArrayType();
Type twoDimArrayType = typeParams[0].MakeArrayType(2);

// Create the array of parameter types.
Type[] parameterTypes = { byRefType, pointerType, arrayType };

// Define the abstract Test method. 
MethodBuilder myMethodBuilder = myType.DefineMethod(
    MethodAttributes.Abstract | MethodAttributes.Virtual
    | MethodAttributes.Public,

// Create the type.


Supported in: 5, 4, 3

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

© 2014 Microsoft. All rights reserved.