public AddInterfaceImplementation ( System interfaceType ) : void | ||
interfaceType | System | |
return | void |
using System; using System.Reflection; using System.Reflection.Emit; public class Program { public static void Main() { var assemblyName = new AssemblyName("MyAssembly"); var assemblyBuilder = AssemblyBuilder.DefineDynamicAssembly(assemblyName, AssemblyBuilderAccess.Run); var moduleBuilder = assemblyBuilder.DefineDynamicModule("MyModule"); var typeBuilder = moduleBuilder.DefineType("MyType", TypeAttributes.Public | TypeAttributes.Class); typeBuilder.AddInterfaceImplementation(typeof(IDisposable)); var myType = typeBuilder.CreateType(); Console.WriteLine(myType.FullName); // output: "MyType" Console.WriteLine(myType.GetInterfaces()[0].Name); // output: "IDisposable" } }
using System; using System.Reflection; using System.Reflection.Emit; public class Program { public static void Main() { var assemblyName = new AssemblyName("MyAssembly"); var assemblyBuilder = AssemblyBuilder.DefineDynamicAssembly(assemblyName, AssemblyBuilderAccess.Run); var moduleBuilder = assemblyBuilder.DefineDynamicModule("MyModule"); var typeBuilder = moduleBuilder.DefineType("MyType", TypeAttributes.Public | TypeAttributes.Class); typeBuilder.AddInterfaceImplementation(typeof(IDisposable)); typeBuilder.AddInterfaceImplementation(typeof(IComparableThis example is similar to the previous one, except that we add two interfaces to the new type: IDisposable and IComparable)); var myType = typeBuilder.CreateType(); Console.WriteLine(myType.FullName); // output: "MyType" Console.WriteLine(myType.GetInterfaces()[0].Name); // output: "IDisposable" Console.WriteLine(myType.GetInterfaces()[1].Name); // output: "IComparable`1" } }