コード例 #1
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));
                }
            }
コード例 #2
0
            public static SymbolKeyResolution Resolve(SymbolKeyReader reader)
            {
                var cancellationToken = reader.CancellationToken;

                var name      = reader.ReadString();
                var kind      = (SymbolKind)reader.ReadInteger();
                var locations = reader.ReadLocationArray();
                var ordinal   = reader.ReadInteger();

                // First check if we can recover the symbol just through the original location.
                foreach (var loc in locations)
                {
                    var resolutionOpt = reader.ResolveLocation(loc);
                    if (resolutionOpt.HasValue)
                    {
                        var resolution = resolutionOpt.Value;
                        var symbol     = resolution.GetAnySymbol();
                        if (symbol?.Kind == kind &&
                            SymbolKey.Equals(reader.Compilation, name, symbol.Name))
                        {
                            return(resolution);
                        }
                    }
                }

                // Couldn't recover.  See if we can still find a match across the textual drift.
                if (ordinal != int.MaxValue &&
                    TryGetSemanticModel(reader.Compilation, locations[0].SourceTree, out var semanticModel))
                {
                    foreach (var symbol in EnumerateSymbols(semanticModel, kind, name, cancellationToken))
                    {
                        if (symbol.ordinal == ordinal)
                        {
                            return(new SymbolKeyResolution(symbol.symbol));
                        }
                    }
                }

                return(default);
コード例 #3
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());
            }