示例#1
0
        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);
        }
示例#2
0
 public static bool IsExactlyType(ISymbol symbol, Type expectedType)
 => symbol.Name == expectedType.Name &&
 SymbolTypeUtil.MergeContainingNamespaces(symbol) ==
 expectedType.Namespace;
示例#3
0
 public static bool Implements(INamedTypeSymbol symbol, Type type)
 => symbol.AllInterfaces.Any(i => SymbolTypeUtil.IsExactlyType(i, type));
示例#4
0
 public static bool ImplementsGeneric(INamedTypeSymbol symbol, Type type)
 => symbol.AllInterfaces.Any(i => SymbolTypeUtil.MatchesGeneric(i, type));