Example #1
0
 private static bool MatchesName(INamespaceOrTypeSymbol typeOrNamespace, NameAndArity nameAndArity, IEqualityComparer <string> comparer)
 {
     return(typeOrNamespace.TypeSwitch(
                (INamespaceSymbol namespaceSymbol) =>
                comparer.Equals(namespaceSymbol.Name, nameAndArity.Name) && nameAndArity.Arity == 0,
                (INamedTypeSymbol typeSymbol) =>
                comparer.Equals(typeSymbol.Name, nameAndArity.Name) &&
                (nameAndArity.Arity == 0 || nameAndArity.Arity == typeSymbol.TypeArguments.Length)));
 }
Example #2
0
        private static bool MatchesName(INamespaceOrTypeSymbol typeOrNamespace, NameAndArity nameAndArity, IEqualityComparer <string> comparer)
        {
            switch (typeOrNamespace)
            {
            case INamespaceSymbol namespaceSymbol:
                return(comparer.Equals(namespaceSymbol.Name, nameAndArity.Name) && nameAndArity.Arity == 0);

            case INamedTypeSymbol typeSymbol:
                return(comparer.Equals(typeSymbol.Name, nameAndArity.Name) &&
                       (nameAndArity.Arity == 0 || nameAndArity.Arity == typeSymbol.TypeArguments.Length));

            default:
                return(false);
            }
        }
Example #3
0
        private IEnumerable <ISymbol> FindMembers(IEnumerable <INamedTypeSymbol> types, NameAndArity nameAndArity)
        {
            // Get the matching members from all types (including constructors and explicit interface
            // implementations).  If there is a partial method, prefer returning the implementation over
            // the definition (since the definition will not be a candidate for setting a breakpoint).
            var members = types.SelectMany(t => GetMembers(t, nameAndArity.Name))
                          .Select(s => GetPartialImplementationPartOrNull(s) ?? s);

            return(nameAndArity.Arity == 0
                ? members
                : members.OfType <IMethodSymbol>().Where(m => m.TypeParameters.Length == nameAndArity.Arity));
        }
        private IEnumerable<ISymbol> FindMembers(IEnumerable<INamedTypeSymbol> types, NameAndArity nameAndArity)
        {
            // Get the matching members from all types (including constructors and explicit interface
            // implementations).  If there is a partial method, prefer returning the implementation over
            // the definition (since the definition will not be a candidate for setting a breakpoint).
            var members = types.SelectMany(t => GetMembers(t, nameAndArity.Name))
                               .Select(s => GetPartialImplementationPartOrNull(s) ?? s);

            return nameAndArity.Arity == 0
                ? members
                : members.OfType<IMethodSymbol>().Where(m => m.TypeParameters.Length == nameAndArity.Arity);
        }
        private static bool MatchesNames(INamedTypeSymbol type, NameAndArity[] names, IEqualityComparer<string> comparer)
        {
            Debug.Assert(type != null);
            Debug.Assert(names.Length >= 2);

            INamespaceOrTypeSymbol container = type;

            // The last element in "names" is the method/property name, but we're only matching against types here,
            // so we'll skip the last one.
            for (var i = names.Length - 2; i >= 0; i--)
            {
                if (!MatchesName(container, names[i], comparer))
                {
                    return false;
                }

                container = ((INamespaceOrTypeSymbol)container.ContainingType) ?? container.ContainingNamespace;

                // We ran out of containers to match against before we matched all the names, so this type isn't a match.
                if ((container == null) && (i > 0))
                {
                    return false;
                }
            }

            return true;
        }
 private static bool MatchesName(INamespaceOrTypeSymbol typeOrNamespace, NameAndArity nameAndArity, IEqualityComparer<string> comparer)
 {
     switch (typeOrNamespace)
     {
         case INamespaceSymbol namespaceSymbol:
             return comparer.Equals(namespaceSymbol.Name, nameAndArity.Name) && nameAndArity.Arity == 0;
         case INamedTypeSymbol typeSymbol:
             return comparer.Equals(typeSymbol.Name, nameAndArity.Name) &&
                 (nameAndArity.Arity == 0 || nameAndArity.Arity == typeSymbol.TypeArguments.Length);
         default:
             return false;
     }
 }
 private static bool MatchesName(INamespaceOrTypeSymbol typeOrNamespace, NameAndArity nameAndArity, IEqualityComparer<string> comparer)
 {
     return typeOrNamespace.TypeSwitch(
         (INamespaceSymbol namespaceSymbol) =>
             comparer.Equals(namespaceSymbol.Name, nameAndArity.Name) && nameAndArity.Arity == 0,
         (INamedTypeSymbol typeSymbol) =>
             comparer.Equals(typeSymbol.Name, nameAndArity.Name) &&
             (nameAndArity.Arity == 0 || nameAndArity.Arity == typeSymbol.TypeArguments.Length));
 }