Hello LCG
The LCG Hello World example is shown here, simply printing “Hello LCG!” to the screen based on a dynamically generated assembly:
// An assembly...var asm = AppDomain.CurrentDomain.DefineDynamicAssembly( new AssemblyName("LCGDemo"), AssemblyBuilderAccess.Run);// ...contains a module...var mod = asm.DefineDynamicModule("MyModule");// ...contains a type...var tpe = mod.DefineType("Sample");// ...contains a method...var mtd = tpe.DefineMethod("SayHello", MethodAttributes.Public | MethodAttributes.Static);// ...contains a code body...var gen = mtd.GetILGenerator();gen.Emit(OpCodes.Ldstr, "Hello LCG!"); // The mythical infoof(Console.WriteLine(string))gen.Emit(OpCodes.Call, ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access