Creating Exe on the Fly |
Submitted By | User Level | Date of Submission |
Kunal Cheda | Beginner | 06/29/2001 |
RuntimeEmit.cs using System; using System.Runtime; using System.Runtime.Emit; Class RuntimeEmit { public static void Main(String [] args) { AppDomain ad = AppDomain.CurrentDomain; AssemblyName am = new AssemblyName(); am.Name = "TestAsm"; AssemblyBuilder ab = ad.DefineDynamicAssembly(am,AssemblyBuilderAclearcase/" target="_blank" >ccess.Save); ModuleBuilder mb = ab.DefineDynamicModule("testmod","TestAsm.exe"); TypeBuilder tb = mb.DefineType("mytype",TypeAttributes.Public); MethodBuilder metb = tb.DefineMethod("hi",MethodAttributes.Public | MethodAttributes.Static,null,null); mb.SetEntryPoint(metb); ILGenerator il = metb.GetILGenerator(); il.EmitWriteLine("Hello World"); il.Emit(OpCodes.Ret); tb.CreateType(); ab.Save("TestAsm.exe"); } } |