Browse Source

Fix incorrect results in TypeExposedByAnalyzer and TypeUsedByAnalyzer

pull/1213/head
Siegfried Pammer 8 years ago
parent
commit
acd4f0b182
  1. 4
      ILSpy/Analyzers/Builtin/TypeExposedByAnalyzer.cs
  2. 14
      ILSpy/Analyzers/Builtin/TypeUsedByAnalyzer.cs

4
ILSpy/Analyzers/Builtin/TypeExposedByAnalyzer.cs

@ -57,7 +57,7 @@ namespace ICSharpCode.ILSpy.Analyzers.Builtin
if (!context.Language.ShowMember(type)) if (!context.Language.ShowMember(type))
yield break; yield break;
var visitor = new TypeDefinitionUsedVisitor(analyzedType); var visitor = new TypeDefinitionUsedVisitor(analyzedType, true);
foreach (IField field in type.Fields) { foreach (IField field in type.Fields) {
if (TypeIsExposedBy(visitor, field)) if (TypeIsExposedBy(visitor, field))
@ -135,7 +135,7 @@ namespace ICSharpCode.ILSpy.Analyzers.Builtin
p.Type.AcceptVisitor(visitor); p.Type.AcceptVisitor(visitor);
} }
return false; return visitor.Found;
} }
} }
} }

14
ILSpy/Analyzers/Builtin/TypeUsedByAnalyzer.cs

@ -53,7 +53,7 @@ namespace ICSharpCode.ILSpy.Analyzers.Builtin
&& analyzedEntity.MetadataToken == type.MetadataToken) && analyzedEntity.MetadataToken == type.MetadataToken)
yield break; yield break;
var visitor = new TypeDefinitionUsedVisitor(analyzedEntity); var visitor = new TypeDefinitionUsedVisitor(analyzedEntity, false);
foreach (var bt in type.DirectBaseTypes) { foreach (var bt in type.DirectBaseTypes) {
bt.AcceptVisitor(visitor); bt.AcceptVisitor(visitor);
@ -193,9 +193,12 @@ namespace ICSharpCode.ILSpy.Analyzers.Builtin
public bool Found { get; set; } public bool Found { get; set; }
public TypeDefinitionUsedVisitor(ITypeDefinition definition) readonly bool topLevelOnly;
public TypeDefinitionUsedVisitor(ITypeDefinition definition, bool topLevelOnly)
{ {
this.TypeDefinition = definition; this.TypeDefinition = definition;
this.topLevelOnly = topLevelOnly;
} }
public override IType VisitTypeDefinition(ITypeDefinition type) public override IType VisitTypeDefinition(ITypeDefinition type)
@ -204,5 +207,12 @@ namespace ICSharpCode.ILSpy.Analyzers.Builtin
&& TypeDefinition.ParentModule.PEFile == type.ParentModule.PEFile; && TypeDefinition.ParentModule.PEFile == type.ParentModule.PEFile;
return base.VisitTypeDefinition(type); return base.VisitTypeDefinition(type);
} }
public override IType VisitParameterizedType(ParameterizedType type)
{
if (topLevelOnly)
return type.GenericType.AcceptVisitor(this);
return base.VisitParameterizedType(type);
}
} }
} }

Loading…
Cancel
Save