Browse Source

Analyzer: Speed up search for extension methods.

pull/166/head
Daniel Grunwald 15 years ago
parent
commit
c70b5b13c3
  1. 2
      ILSpy/TreeNodes/Analyzer/AnalyzedPropertyAccessorsTreeNode.cs
  2. 26
      ILSpy/TreeNodes/Analyzer/AnalyzedTypeExtensionMethodsTreeNode.cs
  3. 1
      README.txt

2
ILSpy/TreeNodes/Analyzer/AnalyzedPropertyAccessorsTreeNode.cs

@ -21,7 +21,7 @@ using Mono.Cecil;
namespace ICSharpCode.ILSpy.TreeNodes.Analyzer namespace ICSharpCode.ILSpy.TreeNodes.Analyzer
{ {
public sealed class AnalyzedPropertyAccessorsTreeNode : AnalyzerTreeNode internal sealed class AnalyzedPropertyAccessorsTreeNode : AnalyzerTreeNode
{ {
public AnalyzedPropertyAccessorsTreeNode(PropertyDefinition analyzedProperty) public AnalyzedPropertyAccessorsTreeNode(PropertyDefinition analyzedProperty)
{ {

26
ILSpy/TreeNodes/Analyzer/AnalyzedTypeExtensionMethodsTreeNode.cs

@ -74,20 +74,34 @@ namespace ICSharpCode.ILSpy.TreeNodes.Analyzer
private IEnumerable<SharpTreeNode> FindReferencesInType(TypeDefinition type) private IEnumerable<SharpTreeNode> FindReferencesInType(TypeDefinition type)
{ {
if (!HasExtensionAttribute(type))
yield break;
foreach (MethodDefinition method in type.Methods) { foreach (MethodDefinition method in type.Methods) {
if (method.IsStatic && method.HasCustomAttributes) { if (method.IsStatic && HasExtensionAttribute(method)) {
if (method.CustomAttributes.Any(ca => ca.AttributeType.FullName == "System.Runtime.CompilerServices.ExtensionAttribute")) { if (method.HasParameters && method.Parameters[0].ParameterType.Resolve() == analyzedType) {
if (method.HasParameters && method.Parameters[0].ParameterType.Resolve() == analyzedType) { yield return new AnalyzedMethodTreeNode(method);
yield return new AnalyzedMethodTreeNode(method);
}
} }
} }
} }
} }
bool HasExtensionAttribute(ICustomAttributeProvider p)
{
if (p.HasCustomAttributes) {
foreach (CustomAttribute ca in p.CustomAttributes) {
TypeReference t = ca.AttributeType;
if (t.Name == "ExtensionAttribute" && t.Namespace == "System.Runtime.CompilerServices")
return true;
}
}
return false;
}
public static bool CanShow(TypeDefinition type) public static bool CanShow(TypeDefinition type)
{ {
return !(type.IsEnum); // show on all types except static classes
return !(type.IsAbstract && type.IsSealed);
} }
} }
} }

1
README.txt

@ -13,5 +13,6 @@ Included open-source libraries:
ILSpy Contributors: ILSpy Contributors:
Daniel Grunwald Daniel Grunwald
David Srbecky David Srbecky
Ed Harvey
Siegfried Pammer Siegfried Pammer
Artur Zgodziński Artur Zgodziński

Loading…
Cancel
Save