示例#1
0
        internal static async Task TestSymbolIdMatchesMetadataAsync(string projectLanguage)
        {
            var metadataSource =
                @"[assembly: System.Reflection.AssemblyVersion(""2.0.0.0"")] public class C { }";
            var symbolName = "C";

            using var context = TestContext.Create(
                      projectLanguage,
                      SpecializedCollections.SingletonEnumerable(metadataSource)
                      );
            var metadataSymbol = await context.ResolveSymbolAsync(symbolName);

            var metadataSymbolId = metadataSymbol.GetSymbolKey();
            var generatedFile    = await context.GenerateSourceAsync(symbolName);

            var generatedDocument    = context.GetDocument(generatedFile);
            var generatedCompilation = await generatedDocument.Project.GetCompilationAsync();

            var generatedSymbol = generatedCompilation.Assembly.GetTypeByMetadataName(symbolName);

            Assert.False(generatedSymbol.Locations.Where(loc => loc.IsInSource).IsEmpty());
            Assert.True(
                SymbolKey
                .GetComparer(ignoreCase: true, ignoreAssemblyKeys: false)
                .Equals(metadataSymbolId, generatedSymbol.GetSymbolKey())
                );
        }
示例#2
0
 public NavigationBarSymbolIdIndexProvider(bool caseSensitive)
 {
     _nextIds = new Dictionary <SymbolKey, int>(
         caseSensitive
           ? SymbolKey.GetComparer(ignoreCase: true, ignoreAssemblyKeys: false)
           : SymbolKey.GetComparer(ignoreCase: false, ignoreAssemblyKeys: false)
         );
 }
示例#3
0
        internal static ISymbol ResolveSymbol(ISymbol originalSymbol, Compilation targetCompilation, SymbolKeyComparison comparison)
        {
            var sid = SymbolKey.Create(originalSymbol, CancellationToken.None);

            // Verify that serialization works.
            var serialized   = sid.ToString();
            var deserialized = new SymbolKey(serialized);
            var comparer     = SymbolKey.GetComparer(ignoreCase: false, ignoreAssemblyKeys: false);

            Assert.True(comparer.Equals(sid, deserialized));

            var symInfo = sid.Resolve(targetCompilation, (comparison & SymbolKeyComparison.IgnoreAssemblyIds) == SymbolKeyComparison.IgnoreAssemblyIds);

            return(symInfo.Symbol);
        }