Example #1
0
        public override void Apply(ModuleDefinition module)
        {
            var method = module.GetMethod("System.Void Aura.Shared.Util.CliUtil::WriteHeader(System.String,System.ConsoleColor)");

            method.Body.SimplifyMacros();

            var bylineWrite = method.Body.Instructions.First(i => i.OpCode == OpCodes.Ldstr && i.Operand.ToString().Contains("by the"));

            do
            {
                bylineWrite = bylineWrite.Next;
            } while (!bylineWrite.Operand.ToString().Contains("System.Console::Write"));

            var il = method.Body.GetILProcessor();

            il.InsertAfter(bylineWrite,
                il.Create(OpCodes.Ldc_I4, (int)ConsoleColor.Yellow),
                il.Create(OpCodes.Call, module.Resolve(typeof(Console), "set_ForegroundColor")),
                il.Create(OpCodes.Ldstr, "                            == RADIATION Edition ==                             "),
                il.Create(OpCodes.Call, module.Resolve(typeof(Console), "Write", typeof(string)))
            );

            method.Body.OptimizeMacros();
        }
        public static IEnumerable<Instruction> BuildTypeCheckRelatedInstructions(ModuleDefinition module, object parameterDefinitionOrFieldDefinition, CustomAttribute attribute)
        {
            var typeReference = (TypeReference)attribute.ConstructorArguments[0].Value;
            foreach (var instruction in BuildDefaultInstructionsInternal(parameterDefinitionOrFieldDefinition))
            {
                yield return instruction;
            }

            var importedGetTypeFromHandle = module.Import(module.GetMethod("GetTypeFromHandle"));

            yield return Instruction.Create(OpCodes.Ldtoken, typeReference);
            yield return Instruction.Create(OpCodes.Call, importedGetTypeFromHandle);
        }