TypeBuilder::AddInterfaceImplementation Method (Type^)
.NET Framework (current version)
Adds an interface that this type implements.
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
Available since 1.1
Silverlight
Available since 2.0
Show: