TypeBuilder.MakePointerType Method

Returns a Type object that represents the type of an unmanaged pointer to the current type.

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

'Declaration
Public Overrides Function MakePointerType As Type

Return Value

Type: System.Type
The type of an unmanaged pointer to the current type.

The MakePointerType method provides a way to generate pointer types for parameter lists.

NoteNote:

Using Microsoft intermediate language (MSIL) syntax, if the current TypeBuilder represents MyType, then the type returned by this method would be MyType*.

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


Imports System.Reflection
Imports System.Reflection.Emit

Public Class Example

   Public Shared Sub Demo(ByVal outputBlock As System.Windows.Controls.TextBlock)

      ' Define a dynamic assembly to contain the sample type. In Silverlight,
      ' a dynamic assembly contains exactly one module.
      '
      Dim myDomain As AppDomain = AppDomain.CurrentDomain
      Dim myAsmName As New AssemblyName("MakeXxxTypeExample")
      Dim myAssembly As AssemblyBuilder = myDomain.DefineDynamicAssembly( _
          myAsmName, _
          AssemblyBuilderAccess.Run)
      Dim myModule As ModuleBuilder = myAssembly.DefineDynamicModule( _
          myAsmName.Name)

      ' Define the sample type.
      Dim myType As TypeBuilder = myModule.DefineType( _
          "Sample", _
          TypeAttributes.Public Or TypeAttributes.Abstract)

      ' Define a method that takes a ByRef argument of type Sample,
      ' a pointer to type Sample, and an array of Sample objects. The
      ' method returns a two-dimensional array of Sample objects.
      '
      ' 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.
      '
      Dim byRefMyType As Type = myType.MakeByRefType
      Dim pointerMyType As Type = myType.MakePointerType
      Dim arrayMyType As Type = myType.MakeArrayType
      Dim twoDimArrayMyType As Type = myType.MakeArrayType(2)

      ' Create the array of parameter types.
      Dim parameterTypes() As Type = _
          {byRefMyType, pointerMyType, arrayMyType}

      ' Define the abstract Test method.
      '
      Dim myMethodBuilder As MethodBuilder = myType.DefineMethod( _
          "TestMethod", _
          MethodAttributes.Abstract Or MethodAttributes.Virtual _
              Or MethodAttributes.Public, _
          twoDimArrayMyType, _
          parameterTypes)

      ' Create the type.
      '
      Dim t As Type = myType.CreateType()

      outputBlock.Text &= "TestMethod takes:" & vbLf
      outputBlock.Text &= "    A ByRef parameter of type Sample." & vbLf
      outputBlock.Text &= "    A pointer to a Sample." & vbLf
      outputBlock.Text &= "    A one-dimensional array of Sample objects." & vbLf
      outputBlock.Text &= "TestMethod returns: A one-dimensional array of Sample objects." & vbLf &vbLf

      outputBlock.Text &= t.GetMethod("TestMethod").ToString()

   End Sub
End Class

' This code produces the following output:
'
'TestMethod takes:" & vbLf
'    A ByRef parameter of type Sample.
'    A pointer to a Sample.
'    A one-dimensional array of Sample objects.
'TestMethod returns: A one-dimensional array of Sample objects.
'
'Sample[,] TestMethod(Sample ByRef, Sample*, Sample[])


Silverlight

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.

Community Additions

ADD
Show: