public static void Create(ISymbol symbol, SymbolKeyWriter visitor)
            {
                Debug.Assert(symbol.IsAnonymousDelegateType() || symbol.IsAnonymousFunction());

                // Write out if this was an anonymous delegate or anonymous function.
                // In both cases they'll have the same location (the location of
                // the lambda that forced them into existence).  When we resolve the
                // symbol later, if it's an anonymous delegate, we'll first resolve to
                // the anonymous-function, then use that anonymous-functoin to get at
                // the synthesized anonymous delegate.
                visitor.WriteBoolean(symbol.IsAnonymousDelegateType());
                visitor.WriteLocation(symbol.Locations.First());
            }
            public static void Create(ISymbol symbol, SymbolKeyWriter visitor)
            {
                Debug.Assert(symbol.IsAnonymousDelegateType() || symbol.IsAnonymousFunction());

                // Write out if this was an anonymous delegate or anonymous function.
                // In both cases they'll have the same location (the location of 
                // the lambda that forced them into existence).  When we resolve the
                // symbol later, if it's an anonymous delegate, we'll first resolve to
                // the anonymous-function, then use that anonymous-functoin to get at
                // the synthesized anonymous delegate.
                visitor.WriteBoolean(symbol.IsAnonymousDelegateType());
                visitor.WriteLocation(symbol.Locations.FirstOrDefault());
            }
 public static void Create(ITypeParameterSymbol symbol, SymbolKeyWriter visitor)
 {
     if (symbol.TypeParameterKind == TypeParameterKind.Cref)
     {
         visitor.WriteBoolean(true);
         visitor.WriteLocation(symbol.Locations[0]);
     }
     else
     {
         visitor.WriteBoolean(false);
         visitor.WriteString(symbol.MetadataName);
         visitor.WriteSymbolKey(symbol.ContainingSymbol);
     }
 }
Exemplo n.º 4
0
            public static void Create(ISymbol symbol, SymbolKeyWriter visitor)
            {
                var containingSymbol = symbol.ContainingSymbol;

                while (containingSymbol.DeclaringSyntaxReferences.IsDefaultOrEmpty)
                {
                    containingSymbol = containingSymbol.ContainingSymbol;
                }

                var compilation = ((ISourceAssemblySymbol)symbol.ContainingAssembly).Compilation;
                var kind        = symbol.Kind;
                var localName   = symbol.Name;

                // Use two mechanisms to try to find the symbol across compilations. First, we use a whitespace
                // insensitive system where we keep track of the list of all locals in the container and we just store
                // our index in it.
                //
                // The above works for cases where the symbol has a real declaration and can be found by walking the
                // declarations of the container.  However, not all symbols can be found that way.  For example, error
                // locals in VB can't be found using GetDeclaredSymbol.  For those, we store the actual local span and
                // use GetSymbolInfo to find it.
                var ordinal = GetOrdinal();

                visitor.WriteString(localName);
                visitor.WriteSymbolKey(containingSymbol);
                visitor.WriteInteger(ordinal);
                visitor.WriteLocation(symbol.Locations[0]);
                visitor.WriteInteger((int)kind);

                return;

                int GetOrdinal()
                {
                    foreach (var possibleSymbol in EnumerateSymbols(compilation, containingSymbol, kind, localName, visitor.CancellationToken))
                    {
                        if (possibleSymbol.symbol.Equals(symbol))
                        {
                            return(possibleSymbol.ordinal);
                        }
                    }

                    return(int.MaxValue);
                }
            }