public void Execute([NotNull] MethodDefinition getInterceptor, [NotNull] MethodDefinition setInterceptor) { // ReSharper disable once AssignNullToNotNullAttribute var backingField = _property.FindAutoPropertyBackingField(_classDefinition.Fields); if (backingField == null) { _logger.LogInfo($"\tSkip {_property.Name}, not an auto-property"); return; } _logger.LogInfo($"\tIntercept {_property.Name}"); var newGetter = BuildGetter(backingField, getInterceptor); var newSetter = BuildSetter(backingField, setInterceptor); foreach (var constructor in _classDefinition.GetConstructors()) { constructor.ReplaceFieldAccessWithPropertySetter(backingField, _property, _classWeaver._weaver._moduleDefinition.SymbolReader); } if (!_isBackingFieldAccessed) { if (_classDefinition.GetConstructors().Any(ctor => ctor.AccessesMember(backingField))) { throw new WeavingException($"The auto-property {_property} is inline initialized and cannot be intercepted.", _property.GetMethod ?? _property.SetMethod); } _logger.LogDebug($"\t\tRemove backing field for {_property.Name}"); _classDefinition.Fields.Remove(backingField); } else { _logger.LogDebug($"\t\tPreserve backing field for {_property.Name} because an interceptor uses it."); } _property.GetMethod?.Body?.Instructions.Replace(newGetter); _property.SetMethod?.Body?.Instructions.Replace(newSetter); }