I'm trying to write an analyzer that checks if a method is implementing an interface method (implicitly), which is easily missed if an interface is providing default implementation. Given a list of potential method symbols on class and obtaining a list of all methods on all interfaces the class implements, I'm doing the following
classMethods
.Where(methodSymbol => !interfaceMethods
.Any(x =>
x.Name == methodSymbol.Name &&
SymbolEqualityComparer.Default.Equals(x.ReturnType, methodSymbol.ReturnType) &&
x.Parameters.Select(p => p.Type).SequenceEqual(methodSymbol.Parameters.Select(p => p.Type))))
This mainly works except for instances where generics are used, such as in the following:
class A : IA
{
public void MethodName<T>(List<T> a) {}
}
interface IA
{
public void MethodName<T>(List<T> a) {}
}
The two types are different from SemanticModel perspective. Is there a way to get generics parameter data? I really would prefer to avoid falling back to syntax model to decypher that T in both means the same thing.