Browse Source

Removed redundant code in type 'used-by' analyzer

pull/569/head
Ed Harvey 11 years ago
parent
commit
ba12fb0742
  1. 28
      ILSpy/TreeNodes/Analyzer/AnalyzedTypeUsedByTreeNode.cs

28
ILSpy/TreeNodes/Analyzer/AnalyzedTypeUsedByTreeNode.cs

@ -60,7 +60,7 @@ namespace ICSharpCode.ILSpy.TreeNodes.Analyzer
if (IsUsedInTypeDefinition(type)) if (IsUsedInTypeDefinition(type))
yield return new AnalyzedTypeTreeNode(type) { Language = Language }; yield return new AnalyzedTypeTreeNode(type) { Language = Language };
foreach (var field in type.Fields.Where(IsUsedInFieldDefinition)) foreach (var field in type.Fields.Where(IsUsedInFieldReference))
yield return new AnalyzedFieldTreeNode(field) { Language = Language }; yield return new AnalyzedFieldTreeNode(field) { Language = Language };
foreach (var method in type.Methods.Where(IsUsedInMethodDefinition)) foreach (var method in type.Methods.Where(IsUsedInMethodDefinition))
@ -94,8 +94,7 @@ namespace ICSharpCode.ILSpy.TreeNodes.Analyzer
{ {
return IsUsedInTypeReference(type) return IsUsedInTypeReference(type)
|| TypeMatches(type.BaseType) || TypeMatches(type.BaseType)
|| IsUsedInTypeReferences(type.Interfaces) || IsUsedInTypeReferences(type.Interfaces);
|| IsUsedInCustomAttributes(type.CustomAttributes);
} }
private bool IsUsedInFieldReference(FieldReference field) private bool IsUsedInFieldReference(FieldReference field)
@ -107,12 +106,6 @@ namespace ICSharpCode.ILSpy.TreeNodes.Analyzer
|| TypeMatches(field.FieldType); || TypeMatches(field.FieldType);
} }
private bool IsUsedInFieldDefinition(FieldDefinition field)
{
return IsUsedInFieldReference(field)
|| IsUsedInCustomAttributes(field.CustomAttributes);
}
private bool IsUsedInMethodReference(MethodReference method) private bool IsUsedInMethodReference(MethodReference method)
{ {
if (method == null) if (method == null)
@ -126,8 +119,7 @@ namespace ICSharpCode.ILSpy.TreeNodes.Analyzer
private bool IsUsedInMethodDefinition(MethodDefinition method) private bool IsUsedInMethodDefinition(MethodDefinition method)
{ {
return IsUsedInMethodReference(method) return IsUsedInMethodReference(method)
|| IsUsedInMethodBody(method) || IsUsedInMethodBody(method);
|| IsUsedInCustomAttributes(method.CustomAttributes);
} }
private bool IsUsedInMethodBody(MethodDefinition method) private bool IsUsedInMethodBody(MethodDefinition method)
@ -167,19 +159,7 @@ namespace ICSharpCode.ILSpy.TreeNodes.Analyzer
private bool IsUsedInMethodParameter(ParameterDefinition parameter) private bool IsUsedInMethodParameter(ParameterDefinition parameter)
{ {
return TypeMatches(parameter.ParameterType) return TypeMatches(parameter.ParameterType);
|| IsUsedInCustomAttributes(parameter.CustomAttributes);
}
private bool IsUsedInCustomAttributes(IEnumerable<CustomAttribute> attributes)
{
return attributes.Any(IsUsedInCustomAttribute);
}
private bool IsUsedInCustomAttribute(CustomAttribute attribute)
{
// No need search in custom attribute, ILSpy already provide an "Applied To" search.
return false;
} }
private bool TypeMatches(TypeReference tref) private bool TypeMatches(TypeReference tref)

Loading…
Cancel
Save