private bool ProcessSequence(InstructionSequence sequence, string extensionMethodName, Func <AutoPropertyInfo, Instruction> createInstruction) { for (var index = 0; index < sequence.Count; index++) { var instruction = sequence[index]; if (!instruction.IsExtensionMethodCall(extensionMethodName)) { continue; } if (sequence.Count < 4 || sequence[0].OpCode != OpCodes.Ldarg_0 || !sequence[1].IsPropertyGetterCall(out string?propertyName) || sequence.Skip(index + 1).Any(inst => inst?.OpCode != OpCodes.Nop) || !_autoPropertyToBackingFieldMap.TryGetValue(propertyName, out var propertyInfo)) { var message = $"Invalid usage of extension method '{extensionMethodName}()': '{extensionMethodName}()' is only valid on auto-properties of class {_method.DeclaringType?.Name}"; _logger.LogError(message, sequence.Point); return(false); } _logger.LogInfo($"Replace {extensionMethodName}() on property {propertyName} in method {_method}."); sequence[index] = createInstruction(propertyInfo !); sequence.RemoveAt(1); return(true); } return(true); }