public static Type CreateTypeImpIGetString() { var typeBuilder = new ClassTypeBuilder(); typeBuilder.DefineType("TempAssembly", "TempAssembly", "GetClass", new[] { typeof(IGetString) }); var getMethodBdr = typeBuilder.DefineMethod("Get", typeof(string), MethodAttributes.Public | MethodAttributes.HideBySig | MethodAttributes.NewSlot | MethodAttributes.Virtual | MethodAttributes.Final, typeof(IGetString).GetMethod("Get")); var getMethodIl = getMethodBdr.GetILGenerator(); getMethodIl.Emit(OpCodes.Ldstr, "Aloha"); getMethodIl.Emit(OpCodes.Ret); return(typeBuilder.CreateType()); }
public static Type DynamicPointTypeGen() { var classTypeBuilder = new ClassTypeBuilder(); classTypeBuilder.DefineType("MyDynamicAssembly", "PointModule", "Point", Type.EmptyTypes); classTypeBuilder.DefineField("x", typeof(int), FieldAttributes.Public); classTypeBuilder.DefineField("y", typeof(int), FieldAttributes.Public); classTypeBuilder.DefineField("z", typeof(int), FieldAttributes.Public); classTypeBuilder.DefineConstructor0("x", "y", "z"); classTypeBuilder.GetFieldMethodImp("x", "GetX", MethodAttributes.Public); classTypeBuilder.GetFieldMethodImp("y", "GetY", MethodAttributes.Public); classTypeBuilder.GetFieldMethodImp("z", "GetZ", MethodAttributes.Public); return(classTypeBuilder.CreateType()); }