Windows apps
Collapse the table of content
Expand the table of content
Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

TypeBuilder::AddInterfaceImplementation Method (Type^)

 

Adds an interface that this type implements.

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

public:
[ComVisibleAttribute(true)]
void AddInterfaceImplementation(
	Type^ interfaceType
)

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( IHello::typeid );
MethodBuilder^ myMethodBuilder =
   helloWorldTypeBuilder->DefineMethod( "SayHello",
      (MethodAttributes)(MethodAttributes::Public | MethodAttributes::Virtual),
      nullptr,
      nullptr );
// Generate IL for 'SayHello' method.
ILGenerator^ myMethodIL = myMethodBuilder->GetILGenerator();
myMethodIL->EmitWriteLine( myGreetingField );
myMethodIL->Emit( OpCodes::Ret );
MethodInfo^ sayHelloMethod = IHello::typeid->GetMethod( "SayHello" );
helloWorldTypeBuilder->DefineMethodOverride( myMethodBuilder, sayHelloMethod );

.NET Framework
Available since 1.1
Silverlight
Available since 2.0
Return to top
Show:
© 2017 Microsoft