TypeBuilder.AddInterfaceImplementation(Type) Méthode
Définition
Important
Certaines informations portent sur la préversion du produit qui est susceptible d’être en grande partie modifiée avant sa publication. Microsoft exclut toute garantie, expresse ou implicite, concernant les informations fournies ici.
Ajoute une interface que ce type implémente.
public:
void AddInterfaceImplementation(Type ^ interfaceType);
public void AddInterfaceImplementation(Type interfaceType);
[System.Runtime.InteropServices.ComVisible(true)]
public void AddInterfaceImplementation(Type interfaceType);
member this.AddInterfaceImplementation : Type -> unit
[<System.Runtime.InteropServices.ComVisible(true)>]
member this.AddInterfaceImplementation : Type -> unit
Public Sub AddInterfaceImplementation (interfaceType As Type)
Paramètres
- interfaceType
- Type
Interface que ce type implémente.
- Attributs
Exceptions
interfaceType a la valeur null.
Le type a été créé précédemment à l’aide CreateType()de .
Exemples
L’exemple de code suivant illustre l’implémentation d’une interface sur un type créé dynamiquement à l’aide AddInterfaceImplementationde .
// Mark the class as implementing 'IHello' interface.
helloWorldTypeBuilder.AddInterfaceImplementation(typeof(IHello));
MethodBuilder myMethodBuilder =
helloWorldTypeBuilder.DefineMethod("SayHello",
MethodAttributes.Public|MethodAttributes.Virtual,
null,
null);
// Generate IL for 'SayHello' method.
ILGenerator myMethodIL = myMethodBuilder.GetILGenerator();
myMethodIL.EmitWriteLine(myGreetingField);
myMethodIL.Emit(OpCodes.Ret);
MethodInfo sayHelloMethod = typeof(IHello).GetMethod("SayHello");
helloWorldTypeBuilder.DefineMethodOverride(myMethodBuilder,sayHelloMethod);
' 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)