diff --git a/ILSpy/Analyzers/Builtin/PropertyOverriddenByAnalyzer.cs b/ILSpy/Analyzers/Builtin/PropertyOverriddenByAnalyzer.cs new file mode 100644 index 000000000..bc451b611 --- /dev/null +++ b/ILSpy/Analyzers/Builtin/PropertyOverriddenByAnalyzer.cs @@ -0,0 +1,40 @@ +using System; +using System.Collections.Generic; +using System.ComponentModel.Composition; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using ICSharpCode.Decompiler.TypeSystem; + +namespace ICSharpCode.ILSpy.Analyzers.Builtin +{ + /// + /// Shows properties that override a property. + /// + [Export(typeof(IAnalyzer))] + class PropertyOverriddenByAnalyzer : ITypeDefinitionAnalyzer + { + public string Text => "Overridden By"; + + public IEnumerable Analyze(IProperty analyzedEntity, ITypeDefinition type, AnalyzerContext context) + { + if (!analyzedEntity.DeclaringType.GetAllBaseTypeDefinitions() + .Any(t => t.MetadataToken == analyzedEntity.DeclaringTypeDefinition.MetadataToken && t.ParentAssembly.PEFile == type.ParentAssembly.PEFile)) + yield break; + + foreach (var property in type.Properties) { + if (!property.IsOverride) continue; + if (InheritanceHelper.GetBaseMembers(property, false) + .Any(p => p.MetadataToken == analyzedEntity.MetadataToken && + p.ParentAssembly.PEFile == analyzedEntity.ParentAssembly.PEFile)) { + yield return property; + } + } + } + + public bool Show(IProperty entity) + { + return entity.IsOverridable && entity.DeclaringType.Kind != TypeKind.Interface; + } + } +} diff --git a/ILSpy/ILSpy.csproj b/ILSpy/ILSpy.csproj index 6da2b6692..97410ae48 100644 --- a/ILSpy/ILSpy.csproj +++ b/ILSpy/ILSpy.csproj @@ -68,6 +68,7 @@ + @@ -226,6 +227,7 @@ + LGPL.txt