Beispiel #1
0
        private static ISymbol TryGetSymbol(NameSyntax name, SymbolInfo symbolInfo, SemanticModel semanticModel)
        {
            if (symbolInfo.Symbol == null && symbolInfo.CandidateSymbols.Length > 0)
            {
                var firstSymbol = symbolInfo.CandidateSymbols[0];

                switch (symbolInfo.CandidateReason)
                {
                case CandidateReason.NotAValue:
                    return(firstSymbol);

                case CandidateReason.NotCreatable:
                    // We want to color types even if they can't be constructed.
                    if (firstSymbol.IsConstructor() || firstSymbol is ITypeSymbol)
                    {
                        return(firstSymbol);
                    }

                    break;

                case CandidateReason.OverloadResolutionFailure:
                    // If we couldn't bind to a constructor, still classify the type.
                    if (firstSymbol.IsConstructor())
                    {
                        return(firstSymbol);
                    }

                    break;

                case CandidateReason.Inaccessible:
                    // If a constructor wasn't accessible, still classify the type if it's accessible.
                    if (firstSymbol.IsConstructor() && semanticModel.IsAccessible(name.SpanStart, firstSymbol.ContainingType))
                    {
                        return(firstSymbol);
                    }

                    break;

                case CandidateReason.WrongArity:
                    if (name.GetRightmostName().Arity == 0)
                    {
                        // When the user writes something like "IList" we don't want to *not* classify
                        // just because the type bound to "IList<T>".  This is also important for use
                        // cases like "Add-using" where it can be confusing when the using is added for
                        // "using System.Collection.Generic" but then the type name still does not classify.
                        return(firstSymbol);
                    }

                    break;
                }
            }

            return(symbolInfo.Symbol);
        }