Browse Source

Add PropertyOverriddenByAnalyzer

pull/1030/head
Siegfried Pammer 7 years ago
parent
commit
2e61aba8f2
  1. 40
      ILSpy/Analyzers/Builtin/PropertyOverriddenByAnalyzer.cs
  2. 2
      ILSpy/ILSpy.csproj

40
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
{
/// <summary>
/// Shows properties that override a property.
/// </summary>
[Export(typeof(IAnalyzer<IProperty>))]
class PropertyOverriddenByAnalyzer : ITypeDefinitionAnalyzer<IProperty>
{
public string Text => "Overridden By";
public IEnumerable<IEntity> 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;
}
}
}

2
ILSpy/ILSpy.csproj

@ -68,6 +68,7 @@
<Compile Include="AboutPage.cs" /> <Compile Include="AboutPage.cs" />
<Compile Include="Analyzers\Builtin\MethodUsedByAnalyzer.cs" /> <Compile Include="Analyzers\Builtin\MethodUsedByAnalyzer.cs" />
<Compile Include="Analyzers\Builtin\MethodUsesAnalyzer.cs" /> <Compile Include="Analyzers\Builtin\MethodUsesAnalyzer.cs" />
<Compile Include="Analyzers\Builtin\PropertyOverriddenByAnalyzer.cs" />
<Compile Include="Analyzers\Builtin\TypeExposedByAnalyzer.cs" /> <Compile Include="Analyzers\Builtin\TypeExposedByAnalyzer.cs" />
<Compile Include="Analyzers\Builtin\TypeInstantiatedByAnalyzer.cs" /> <Compile Include="Analyzers\Builtin\TypeInstantiatedByAnalyzer.cs" />
<Compile Include="Analyzers\Builtin\TypeUsedByAnalyzer.cs" /> <Compile Include="Analyzers\Builtin\TypeUsedByAnalyzer.cs" />
@ -226,6 +227,7 @@
<Compile Include="TreeNodes\ResourceNodes\XamlResourceNode.cs" /> <Compile Include="TreeNodes\ResourceNodes\XamlResourceNode.cs" />
<Compile Include="TreeNodes\ResourceNodes\XmlResourceNode.cs" /> <Compile Include="TreeNodes\ResourceNodes\XmlResourceNode.cs" />
<Compile Include="TreeNodes\SearchMsdnContextMenuEntry.cs" /> <Compile Include="TreeNodes\SearchMsdnContextMenuEntry.cs" />
<Compile Include="TypeExtensionMethodsAnalyzer.cs" />
<EmbeddedResource Include="..\doc\LGPL.txt"> <EmbeddedResource Include="..\doc\LGPL.txt">
<Link>LGPL.txt</Link> <Link>LGPL.txt</Link>
</EmbeddedResource> </EmbeddedResource>

Loading…
Cancel
Save