Roslyn - Is symbol implementation of interface?
Sure its possible.
Just for your Dispose
example:
var disposeMethodSymbol = ...
var type = disposeMethodSymbol.ContainingType;
var isInterfaceImplementaton = type.FindImplementationForInterfaceMember(
type.Interfaces.Single().
GetMembers().OfType<IMethodSymbol>().Single()) == disposeMethodSymbol ;
But if it for general use you need to write it more generally, use AllInterfaces
and not Interfaces
and sure not use Single
.
Example:
public static bool IsInterfaceImplementation(this IMethodSymbol method)
{
return method.ContainingType.AllInterfaces.SelectMany(@interface => @interface.GetMembers().OfType<IMethodSymbol>()).Any(interfaceMethod => method.ContainingType.FindImplementationForInterfaceMember(interfaceMethod).Equals(method));
}