public static SymbolKeyResolution Resolve(SymbolKeyReader reader)
            {
                var isAnonymousDelegateType = reader.ReadBoolean();
                var location = reader.ReadLocation();

                var syntaxTree = location.SourceTree;

                if (syntaxTree == null)
                {
                    return(default(SymbolKeyResolution));
                }

                var semanticModel = reader.Compilation.GetSemanticModel(syntaxTree);
                var root          = syntaxTree.GetRoot(reader.CancellationToken);
                var node          = root.FindNode(location.SourceSpan, getInnermostNodeForTie: true);

                var symbol = semanticModel.GetSymbolInfo(node, reader.CancellationToken)
                             .GetAnySymbol();

                // If this was a key for an anonymous delegate type, then go find the
                // associated delegate for this lambda and return that instead of the
                // lambda function symbol itself.
                if (isAnonymousDelegateType)
                {
                    var anonymousDelegate = (symbol as IMethodSymbol).AssociatedAnonymousDelegate;
                    symbol = anonymousDelegate;
                }

                return(new SymbolKeyResolution(symbol));
            }
예제 #2
0
            public static SymbolKeyResolution Resolve(SymbolKeyReader reader)
            {
                var isCref = reader.ReadBoolean();

                if (isCref)
                {
                    var location   = reader.ReadLocation();
                    var resolution = reader.ResolveLocation(location);
                    return(resolution.GetValueOrDefault());
                }
                else
                {
                    var metadataName = reader.ReadString();
                    var containingSymbolResolution = reader.ReadSymbolKey();

                    using var result = PooledArrayBuilder <ITypeParameterSymbol> .GetInstance();

                    foreach (var containingSymbol in containingSymbolResolution)
                    {
                        foreach (var typeParam in containingSymbol.GetTypeParameters())
                        {
                            if (typeParam.MetadataName == metadataName)
                            {
                                result.AddIfNotNull(typeParam);
                            }
                        }
                    }

                    return(CreateResolution(result));
                }
            }
예제 #3
0
            public static SymbolKeyResolution Resolve(SymbolKeyReader reader)
            {
                var isAnonymousDelegateType = reader.ReadBoolean();
                var location = reader.ReadLocation();

                var syntaxTree = location.SourceTree;

                if (syntaxTree == null)
                {
                    return(default);
예제 #4
0
            public static SymbolKeyResolution Resolve(SymbolKeyReader reader)
            {
                var cancellationToken = reader.CancellationToken;

                var localName = reader.ReadString();
                var containingSymbolResolution = reader.ReadSymbolKey();
                var ordinal  = reader.ReadInteger();
                var location = reader.ReadLocation();
                var kind     = (SymbolKind)reader.ReadInteger();

                var containingSymbol = containingSymbolResolution.Symbol;

                if (containingSymbol != null)
                {
                    if (ordinal != int.MaxValue)
                    {
                        foreach (var symbol in EnumerateSymbols(reader.Compilation, containingSymbol, kind, localName, cancellationToken))
                        {
                            if (symbol.ordinal == ordinal)
                            {
                                return(new SymbolKeyResolution(symbol.symbol));
                            }
                        }
                    }
                    else
                    {
                        var resolution = reader.ResolveLocation(location);
                        if (resolution != null)
                        {
                            return(resolution.Value);
                        }
                    }
                }

                return(new SymbolKeyResolution());
            }