lGen = methodBuilder.GetILGenerator(); //以下三行相当于:{Console.Writeln("I'm "+ targetMethod.Name +"ing");} ilGen.Emit(OpCodes.Ldstr,"I'm "+ targetMethod.Name +"ing"); ilGen.Emit(OpCodes.Call,typeof(Console).GetMethod("WriteLine",new Type[]{typeof(String)})); ilGen.Emit(OpCodes.Ret); } } //真正创建,并返回 return(typeBuilder.CreateType()); } } 好了,测试一下试试看:using System; public class Tester { public static void Main(String[] args) { TypeCreator tc=new TypeCreator(typeof(IAnimal)); Type t = tc.build(); IAnimal 页码:[1] [2] [3] [4] [5] [6] [7] [8] 第7页、共8页 |