Browse Source

Fix analyzers for properties and events, add missing file.

pull/1030/head
Siegfried Pammer 8 years ago
parent
commit
ffd7d5c71d
  1. 4
      ILSpy/Analyzers/AnalyzeContextMenuEntry.cs
  2. 3
      ILSpy/Analyzers/Builtin/TypeExposedByAnalyzer.cs
  3. 5
      ILSpy/Analyzers/TreeNodes/AnalyzedEventTreeNode.cs
  4. 4
      ILSpy/Analyzers/TreeNodes/AnalyzedPropertyTreeNode.cs
  5. 33
      ILSpy/TypeExtensionMethodsAnalyzer.cs

4
ILSpy/Analyzers/AnalyzeContextMenuEntry.cs

@ -79,10 +79,10 @@ namespace ICSharpCode.ILSpy.Analyzers @@ -79,10 +79,10 @@ namespace ICSharpCode.ILSpy.Analyzers
AnalyzerTreeView.Instance.ShowOrFocus(new AnalyzedMethodTreeNode(md));
break;
case IProperty pd:
//AnalyzerTreeView.Instance.ShowOrFocus(new AnalyzedPropertyTreeNode(pd));
AnalyzerTreeView.Instance.ShowOrFocus(new AnalyzedPropertyTreeNode(pd));
break;
case IEvent ed:
//AnalyzerTreeView.Instance.ShowOrFocus(new AnalyzedEventTreeNode(ed));
AnalyzerTreeView.Instance.ShowOrFocus(new AnalyzedEventTreeNode(ed));
break;
default:
throw new NotSupportedException();

3
ILSpy/Analyzers/Builtin/TypeExposedByAnalyzer.cs

@ -8,6 +8,9 @@ using ICSharpCode.Decompiler.TypeSystem; @@ -8,6 +8,9 @@ using ICSharpCode.Decompiler.TypeSystem;
namespace ICSharpCode.ILSpy.Analyzers.Builtin
{
/// <summary>
/// Finds all entities that expose a type.
/// </summary>
[Export(typeof(IAnalyzer<ITypeDefinition>))]
class TypeExposedByAnalyzer : ITypeDefinitionAnalyzer<ITypeDefinition>
{

5
ILSpy/Analyzers/TreeNodes/AnalyzedEventTreeNode.cs

@ -44,10 +44,9 @@ namespace ICSharpCode.ILSpy.Analyzers.TreeNodes @@ -44,10 +44,9 @@ namespace ICSharpCode.ILSpy.Analyzers.TreeNodes
protected override void LoadChildren()
{
if (analyzedEvent.AddAccessor != null)
if (analyzedEvent.CanAdd)
this.Children.Add(new AnalyzedAccessorTreeNode(analyzedEvent.AddAccessor, "add"));
if (analyzedEvent.RemoveAccessor != null)
if (analyzedEvent.CanRemove)
this.Children.Add(new AnalyzedAccessorTreeNode(analyzedEvent.RemoveAccessor, "remove"));
//foreach (var accessor in analyzedEvent.OtherMethods)

4
ILSpy/Analyzers/TreeNodes/AnalyzedPropertyTreeNode.cs

@ -41,9 +41,9 @@ namespace ICSharpCode.ILSpy.Analyzers.TreeNodes @@ -41,9 +41,9 @@ namespace ICSharpCode.ILSpy.Analyzers.TreeNodes
protected override void LoadChildren()
{
if (!analyzedProperty.CanGet)
if (analyzedProperty.CanGet)
this.Children.Add(new AnalyzedAccessorTreeNode(analyzedProperty.Getter, "get"));
if (!analyzedProperty.CanSet)
if (analyzedProperty.CanSet)
this.Children.Add(new AnalyzedAccessorTreeNode(analyzedProperty.Setter, "set"));
//foreach (var accessor in analyzedProperty.OtherMethods)
// this.Children.Add(new AnalyzedPropertyAccessorTreeNode(accessor, null));

33
ILSpy/TypeExtensionMethodsAnalyzer.cs

@ -0,0 +1,33 @@ @@ -0,0 +1,33 @@
using System.Collections.Generic;
using System.ComponentModel.Composition;
using ICSharpCode.Decompiler.TypeSystem;
namespace ICSharpCode.ILSpy.Analyzers.Builtin
{
/// <summary>
/// Finds all extension methods defined for a type.
/// </summary>
[Export(typeof(IAnalyzer<ITypeDefinition>))]
class TypeExtensionMethodsAnalyzer : ITypeDefinitionAnalyzer<ITypeDefinition>
{
public string Text => "Extension Methods";
public bool Show(ITypeDefinition entity) => !entity.IsStatic;
public IEnumerable<IEntity> Analyze(ITypeDefinition analyzedType, ITypeDefinition type, AnalyzerContext context)
{
if (!type.HasExtensionMethods)
yield break;
foreach (IMethod method in type.Methods) {
if (!method.IsExtensionMethod) continue;
var firstParamType = method.Parameters[0].Type.GetDefinition();
if (firstParamType != null &&
firstParamType.MetadataToken == analyzedType.MetadataToken &&
firstParamType.ParentAssembly.PEFile == analyzedType.ParentAssembly.PEFile)
yield return method;
}
}
}
}
Loading…
Cancel
Save