Пример #1
0
        private void CheckName(string name, SimpleNameSyntax node)
        {
            for (int i = Nodes.Count - 1; i >= 0; i--)
            {
                NodeSymbolInfo info = Nodes[i];

                if (info.Name == name)
                {
                    if (info.Symbol == null)
                    {
                        ISymbol declaredSymbol = SemanticModel.GetDeclaredSymbol(info.Node, CancellationToken);

                        Debug.Assert(declaredSymbol != null, "");

                        if (declaredSymbol == null)
                        {
                            RemoveNodeAt(i);
                            continue;
                        }

                        info = new NodeSymbolInfo(info.Name, info.Node, declaredSymbol);

                        Nodes[i] = info;
                    }

                    ISymbol symbol = SemanticModel.GetSymbol(node, CancellationToken);

                    if (symbol == null)
                    {
                        continue;
                    }

                    if (symbol is IMethodSymbol methodSymbol)
                    {
                        symbol = methodSymbol.ReducedFrom ?? methodSymbol;
                    }

                    if (info.Symbol.Equals(symbol.OriginalDefinition) &&
                        _containingMethodSymbol?.Equals(symbol.OriginalDefinition) != true)
                    {
                        RemoveNodeAt(i);
                    }
                }
            }
        }
Пример #2
0
        private static void RemoveMethodsAndPropertiesThatAreInDebuggerDisplayAttributeValue(
            string value,
            ref Collection<NodeSymbolInfo> nodes)
        {
            int length = value.Length;

            if (length == 0)
                return;

            for (int i = 0; i < length; i++)
            {
                switch (value[i])
                {
                    case '{':
                        {
                            i++;

                            int startIndex = i;

                            while (i < length)
                            {
                                char ch = value[i];

                                if (ch == '}'
                                    || ch == ','
                                    || ch == '(')
                                {
                                    int nameLength = i - startIndex;

                                    if (nameLength > 0)
                                    {
                                        for (int j = nodes.Count - 1; j >= 0; j--)
                                        {
                                            NodeSymbolInfo nodeSymbolInfo = nodes[j];

                                            if (nodeSymbolInfo.CanBeInDebuggerDisplayAttribute
                                                && string.CompareOrdinal(nodeSymbolInfo.Name, 0, value, startIndex, nameLength) == 0)
                                            {
                                                nodes.RemoveAt(j);

                                                if (nodes.Count == 0)
                                                    return;
                                            }
                                        }
                                    }

                                    if (ch != '}')
                                    {
                                        i++;

                                        while (i < length
                                            && value[i] != '}')
                                        {
                                            i++;
                                        }
                                    }

                                    break;
                                }

                                i++;
                            }

                            break;
                        }
                    case '}':
                        {
                            return;
                        }
                    case '\\':
                        {
                            i++;
                            break;
                        }
                }
            }
        }
Пример #3
0
        private void VisitSimpleName(SimpleNameSyntax node, string name)
        {
            for (int i = Nodes.Count - 1; i >= 0; i--)
            {
                NodeSymbolInfo info = Nodes[i];

                if (info.Name == name)
                {
                    if (info.Symbol == null)
                    {
                        ISymbol declaredSymbol = SemanticModel.GetDeclaredSymbol(info.Node, CancellationToken);

                        Debug.Assert(declaredSymbol != null, "");

                        if (declaredSymbol == null)
                        {
                            RemoveNodeAt(i);
                            continue;
                        }

                        info = new NodeSymbolInfo(info.Name, info.Node, declaredSymbol);

                        Nodes[i] = info;
                    }

                    SymbolInfo symbolInfo = SemanticModel.GetSymbolInfo(node, CancellationToken);

                    if (symbolInfo.Symbol != null)
                    {
                        ISymbol symbol = symbolInfo.Symbol;

                        if (symbol.Kind == SymbolKind.Method)
                        {
                            var methodSymbol = ((IMethodSymbol)symbol);

                            if (methodSymbol.MethodKind == MethodKind.ReducedExtension)
                            {
                                symbol = methodSymbol.ReducedFrom;
                            }
                        }

                        symbol = symbol.OriginalDefinition;

                        if (SymbolEqualityComparer.Default.Equals(info.Symbol, symbol) &&
                            !SymbolEqualityComparer.Default.Equals(_containingMethodSymbol, symbol))
                        {
                            RemoveNodeAt(i);
                        }
                    }
                    else if (symbolInfo.CandidateReason == CandidateReason.LateBound)
                    {
                        RemoveNodeAt(i);
                    }
                    else if (symbolInfo.CandidateReason == CandidateReason.MemberGroup ||
                             symbolInfo.CandidateReason == CandidateReason.OverloadResolutionFailure)
                    {
                        ImmutableArray <ISymbol> candidateSymbols = symbolInfo.CandidateSymbols;

                        for (int j = 0; j < candidateSymbols.Length; j++)
                        {
                            ISymbol symbol = candidateSymbols[j].OriginalDefinition;

                            if (SymbolEqualityComparer.Default.Equals(info.Symbol, symbol) &&
                                !SymbolEqualityComparer.Default.Equals(_containingMethodSymbol, symbol))
                            {
                                RemoveNodeAt(i);
                            }
                        }
                    }
                }
            }
        }
Пример #4
0
        private void CheckName(string name, SimpleNameSyntax node)
        {
            for (int i = Nodes.Count - 1; i >= 0; i--)
            {
                NodeSymbolInfo info = Nodes[i];

                if (info.Name == name)
                {
                    if (info.Symbol == null)
                    {
                        ISymbol declaredSymbol = SemanticModel.GetDeclaredSymbol(info.Node, CancellationToken);

                        Debug.Assert(declaredSymbol != null, "");

                        if (declaredSymbol == null)
                        {
                            RemoveNodeAt(i);
                            continue;
                        }

                        info = new NodeSymbolInfo(info.Name, info.Node, declaredSymbol);

                        Nodes[i] = info;
                    }

                    SymbolInfo symbolInfo = SemanticModel.GetSymbolInfo(node, CancellationToken);

                    if (symbolInfo.Symbol != null)
                    {
                        ISymbol symbol = symbolInfo.Symbol;

                        if (symbol.Kind == SymbolKind.Method)
                        {
                            var methodSymbol = ((IMethodSymbol)symbol);

                            if (methodSymbol.MethodKind == MethodKind.ReducedExtension)
                            {
                                symbol = methodSymbol.ReducedFrom;
                            }
                        }

                        symbol = symbol.OriginalDefinition;

                        if (info.Symbol.Equals(symbol) &&
                            _containingMethodSymbol?.Equals(symbol) != true)
                        {
                            RemoveNodeAt(i);
                        }
                    }
                    else if (symbolInfo.CandidateReason == CandidateReason.MemberGroup)
                    {
                        ImmutableArray <ISymbol> candidateSymbols = symbolInfo.CandidateSymbols;

                        for (int j = 0; j < candidateSymbols.Length; j++)
                        {
                            ISymbol symbol = candidateSymbols[j].OriginalDefinition;

                            if (info.Symbol.Equals(symbol) &&
                                _containingMethodSymbol?.Equals(symbol) != true)
                            {
                                RemoveNodeAt(i);
                            }
                        }
                    }
                    else
                    {
                        Debug.Fail(symbolInfo.CandidateReason.ToString());
                    }
                }
            }
        }