dotnet/roslyn

Mechanism for getting from metadata symbol to underlying handle or raw metadata token

Open

#6 749 ouverte le 13 nov. 2015

Voir sur GitHub
 (18 commentaires) (0 réactions) (0 assignés)C# (4 257 forks)batch import
2 - ReadyArea-CompilersConcept-APIFeature Requesthelp wanted

Métriques du dépôt

Stars
 (20 414 stars)
Métriques de merge PR
 (Merge moyen 6j 17h) (256 PRs mergées en 30 j)

Description

It would be useful to be able to correlate a Roslyn symbol originating in metadata to PDBs, IL, and lower level metadata.

I've experimented with it and I'll submit the following two alternative proposals

1. Expose the handle via a new interface that can be queried

https://github.com/dotnet/roslyn/compare/master...nguerrera:metadata-symbol

public interface IMetadataSymbol
{
    System.Reflection.Metadata.Handle MetadataHandle { get; }
}

internal class PENamedTypeSymbol : NamedTypeSymbol, IMetadataSymbol
{
   public System.Reflection.Metadata.Handle MetadataHandle => _handle;
    ..
}

// etc. for all of the PEXxxSymbols for C# and VB.

2. Expose the handle directly from ISymbol

https://github.com/dotnet/roslyn/compare/master...nguerrera:metadata-symbol-2

public interface ISymbol
{
    System.Reflection.Metadata.Handle MetadataHandle { get; }
    ...
}

internal class Symbol : ISymbol
{
     public virtual System.Reflection.Metadata.Handle MetadataHandle => default(Handle);
     ...
}

internal class PENamedTypeSymbol : NamedTypeSymbol
{
    public override System.Reflection.Metadata.Handle MetadataHandle => _handle;
    ...
}

// etc. for all of the PEXxxSymbols for C# and VB.

So non-metadata symbols simply return default(Handle) which has IsNil property equal to true.

I started with (1) under the assumption that we could not modify an existing interface, but I have since learned about Roslyn's "internal-implementation-only" policy for symbols. I now think (2) is much better and cleaner and aligns with the recent addition of Metadata properties on IAssemblySymbol and IModuleSymbol.

Guide contributeur