public static bool MatchesGeneric(INamedTypeSymbol symbol, Type expectedGenericType) { var sameName = symbol.Name == expectedGenericType.Name.Substring( 0, expectedGenericType.Name.IndexOf('`')); var sameNamespace = SymbolTypeUtil.MergeContainingNamespaces(symbol) == expectedGenericType.Namespace; var sameTypeArguments = symbol.TypeArguments.Length == expectedGenericType.GetTypeInfo() .GenericTypeParameters.Length; return(sameName && sameNamespace && sameTypeArguments); }
public static bool IsExactlyType(ISymbol symbol, Type expectedType) => symbol.Name == expectedType.Name && SymbolTypeUtil.MergeContainingNamespaces(symbol) == expectedType.Namespace;
public static bool Implements(INamedTypeSymbol symbol, Type type) => symbol.AllInterfaces.Any(i => SymbolTypeUtil.IsExactlyType(i, type));
public static bool ImplementsGeneric(INamedTypeSymbol symbol, Type type) => symbol.AllInterfaces.Any(i => SymbolTypeUtil.MatchesGeneric(i, type));