static FieldInfo GetBackingField(MethodInfo method, ILPattern pattern) { //Debug.WriteLine("Enter on Reflection.EMIT and works!"); var result = ILPattern.Match(method, pattern); if (!result.success) { throw new NotSupportedException(); } // Debug.WriteLine("Exit on Reflection.EMIT and works!"); return(result.field); }
public static MatchContext Match(MethodBase method, ILPattern pattern) { var instructions = method.GetInstructions(); if (instructions.Count == 0) { throw new ArgumentException(); } var context = new MatchContext(instructions[0]); pattern.Match(context); return(context); }