Repository: dotnet/aspnetcore
File: src/Shared/RoslynUtils/SymbolExtensions.cs (C#)

Code before:

    public static bool HasAttributeInheritingFrom(this ISymbol symbol, INamedTypeSymbol baseType)
    {
        return symbol.TryGetAttributeInheritingFrom(baseType, out var _);
    }

    public static bool TryGetAttributeInheritingFrom(this ISymbol symbol, INamedTypeSymbol baseType, [NotNullWhen(true)] out AttributeData? matchedAttribute)
    {
        foreach (var attributeData in symbol.GetAttributes())
        {
            if (attributeData.AttributeClass is not null && attributeData.AttributeClass.InheritsFrom(baseType))
            {
                matchedAttribute = attributeData;
                return true;
            }
        }

        matchedAttribute = null;
        return false;
    }

    public static bool HasAttributeInheritingFrom(this ImmutableArray<AttributeData> attributes, INamedTypeSymbol baseType)
    {
        return attributes.TryGetAttributeInheritingFrom(baseType, out var _);
    }

    public static bool TryGetAttributeInheritingFrom(this ImmutableArray<AttributeData> attributes, INamedTypeSymbol baseType, [NotNullWhen(true)] out AttributeData? matchedAttribute)
    {
        foreach (var attributeData in attributes)
        {
            if (attributeData.AttributeClass is not null && attributeData.AttributeClass.InheritsFrom(baseType))
            {
                matchedAttribute = attributeData;
                return true;
            }
        }

        matchedAttribute = null;
        return false;
    }

    public static bool Implements(this ITypeSymbol type, ITypeSymbol interfaceType)
    {
        foreach (var t in type.AllInterfaces)
        {
            if (SymbolEqualityComparer.Default.Equals(t, interfaceType))
            {
                return true;
            }
        }
        return false;

Review comment (suggestion):
```suggestion
```

Is any of the above code called anywhere? Even if so, the ISymbol overload of TryGetAttributeInheritingFrom could probably be changed to:

```csharp
    public static bool TryGetAttributeInheritingFrom(this ISymbol symbol, INamedTypeSymbol baseType, [NotNullWhen(true)] out AttributeData? matchedAttribute)
        => TryGetAttributeInheritingFrom(symbol.GetAttributes(), baseType, out matchedAttribute);
```

Code after:

    public static bool HasAttributeInheritingFrom(this ISymbol symbol, INamedTypeSymbol baseType)
    {
        return symbol.TryGetAttributeInheritingFrom(baseType, out var _);
    }

    public static bool TryGetAttributeInheritingFrom(this ISymbol symbol, INamedTypeSymbol baseType, [NotNullWhen(true)] out AttributeData? matchedAttribute)
    {
        return symbol.GetAttributes().TryGetAttributeInheritingFrom(baseType, out matchedAttribute);
    }

    public static bool HasAttributeInheritingFrom(this ImmutableArray<AttributeData> attributes, INamedTypeSymbol baseType)
    {
        return attributes.TryGetAttributeInheritingFrom(baseType, out var _);
    }

    public static bool TryGetAttributeInheritingFrom(this ImmutableArray<AttributeData> attributes, INamedTypeSymbol baseType, [NotNullWhen(true)] out AttributeData? matchedAttribute)
    {
        foreach (var attributeData in attributes)
        {
            if (attributeData.AttributeClass is not null && attributeData.AttributeClass.InheritsFrom(baseType))
            {
                matchedAttribute = attributeData;
                return true;
            }
        }

        matchedAttribute = null;
        return false;
    }

    public static bool Implements(this ITypeSymbol type, ITypeSymbol interfaceType)
    {
        foreach (var t in type.AllInterfaces)
        {
            if (SymbolEqualityComparer.Default.Equals(t, interfaceType))
            {
                return true;
            }
        }
        return false;
    }

    public static bool InheritsFrom(this ITypeSymbol type, ITypeSymbol baseType)
    {
        foreach (var t in type.GetThisAndBaseTypes())
        {
            if (SymbolEqualityComparer.Default.Equals(t, baseType))
            {
                return true;
            }