AddInterfaceImplementation Method

TypeBuilder.AddInterfaceImplementation Method (Type)

 

Adds an interface that this type implements.

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

<ComVisibleAttribute(True)>
Public Sub AddInterfaceImplementation (
	interfaceType As Type
)

Parameters

interfaceType
Type: System.Type

The interface that this type implements.

Exception Condition
ArgumentNullException

interfaceType is null.

InvalidOperationException

The type was previously created using CreateType.

The following code sample demonstrates the implementation of an interface on a dynamically created type using AddInterfaceImplementation.

' Mark the class as implementing 'IHello' interface.
helloWorldTypeBuilder.AddInterfaceImplementation(GetType(IHello))
Dim myMethodBuilder As MethodBuilder = helloWorldTypeBuilder.DefineMethod("SayHello", _
                     MethodAttributes.Public Or MethodAttributes.Virtual, Nothing, Nothing)
' Generate IL for 'SayHello' method.
Dim myMethodIL As ILGenerator = myMethodBuilder.GetILGenerator()
myMethodIL.EmitWriteLine(myGreetingField)
myMethodIL.Emit(OpCodes.Ret)
Dim sayHelloMethod As MethodInfo = GetType(IHello).GetMethod("SayHello")
helloWorldTypeBuilder.DefineMethodOverride(myMethodBuilder, sayHelloMethod)

Universal Windows Platform
Available since 10
.NET Framework
Available since 1.1
Silverlight
Available since 2.0
Return to top
Show:
© 2016 Microsoft