Skip to content

Commit

Permalink
Use GetBaseTypesAndThis()
Browse files Browse the repository at this point in the history
  • Loading branch information
NewellClark committed Jun 6, 2023
1 parent e752b27 commit 5ecdfd6
Showing 1 changed file with 2 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ private static void AnalyzeSymbol(SymbolAnalysisContext symbolContext)
// don't report a diagnostic on the `op_False` method because then the user would see two diagnostics for what is really one error
// special-case looking for `IsTrue` instance property
// named properties can't be overloaded so there will only ever be 0 or 1
IPropertySymbol property = ClassHierarchy(typeSymbol).SelectMany(x => x.GetMembers(IsTrueText).OfType<IPropertySymbol>()).FirstOrDefault();
IPropertySymbol property = typeSymbol.GetBaseTypesAndThis().SelectMany(x => x.GetMembers(IsTrueText).OfType<IPropertySymbol>()).FirstOrDefault();
if (property == null || property.Type.SpecialType != SpecialType.System_Boolean)
{
symbolContext.ReportDiagnostic(CreateDiagnostic(PropertyRule, GetSymbolLocation(methodSymbol), AddAlternateText, IsTrueText, operatorName));
Expand All @@ -125,7 +125,7 @@ private static void AnalyzeSymbol(SymbolAnalysisContext symbolContext)
unmatchedMethods.Add(expectedGroup.AlternateMethod2);
}

foreach (IMethodSymbol candidateMethod in ClassHierarchy(typeSymbol).SelectMany(x => x.GetMembers().OfType<IMethodSymbol>()))
foreach (IMethodSymbol candidateMethod in typeSymbol.GetBaseTypesAndThis().SelectMany(x => x.GetMembers().OfType<IMethodSymbol>()))
{
if (candidateMethod.Name == expectedGroup.AlternateMethod1 || candidateMethod.Name == expectedGroup.AlternateMethod2)
{
Expand Down Expand Up @@ -168,15 +168,6 @@ private static void AnalyzeSymbol(SymbolAnalysisContext symbolContext)
}
}

private static IEnumerable<ITypeSymbol> ClassHierarchy(ITypeSymbol typeSymbol)
{
while (typeSymbol is not null)
{
yield return typeSymbol;
typeSymbol = typeSymbol.BaseType;
}
}

private static Location GetSymbolLocation(ISymbol symbol)
{
return symbol.OriginalDefinition.Locations.First();
Expand Down

0 comments on commit 5ecdfd6

Please sign in to comment.