Exemplo n.º 1
0
        public static string StringOperation(string original)
        {
            // This inner transpiler will be applied to the original and
            // the result will replace this method
            //
            // That will allow this method to have a different signature
            // than the original and it must match the transpiled result
            //
            IEnumerable <CodeInstruction> Transpiler(IEnumerable <CodeInstruction> instructions)
            {
                var list = Transpilers.Manipulator(instructions,
                                                   item => item.opcode == OpCodes.Ldarg_1,
                                                   item => item.opcode = OpCodes.Ldarg_0
                                                   ).ToList();
                var mJoin = SymbolExtensions.GetMethodInfo(() => string.Join(null, null));
                var idx   = list.FindIndex(item => item.opcode == OpCodes.Call && item.operand as MethodInfo == mJoin);

                list.RemoveRange(idx + 1, list.Count - (idx + 1));
                list.Add(new CodeInstruction(OpCodes.Ret));
                return(list.AsEnumerable());
            }

            // make compiler happy
            _ = Transpiler(null);
            return(original);
        }
Exemplo n.º 2
0
        public static string StringOperation(string original)
        {
            IEnumerable <CodeInstruction> Transpiler(IEnumerable <CodeInstruction> instructions)
            {
                var mJoin = SymbolExtensions.GetMethodInfo(() => string.Join(null, null));
                var list  = Transpilers.Manipulator(instructions,
                                                    item => item.opcode == OpCodes.Ldarg_1,
                                                    item => item.opcode = OpCodes.Ldarg_0
                                                    ).ToList();
                var idx = list.FindIndex(item => item.opcode == OpCodes.Call && item.operand == mJoin);

                list.RemoveRange(idx + 1, list.Count - (idx + 1));
                return(list.AsEnumerable());
            }

            Transpiler(null);
            return(original);
        }
Exemplo n.º 3
0
 static IEnumerable <CodeInstruction> Transpiler(IEnumerable <CodeInstruction> instructions)
 {
     return(Transpilers.Manipulator(instructions, instr => instr.OperandIs((int)' '), instr => instr.operand = (int)'*'));
 }