forked from OmniSharp/omnisharp-roslyn
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ISymbolExtensions.cs
71 lines (60 loc) · 1.9 KB
/
ISymbolExtensions.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
using System;
using System.Collections.Generic;
using Microsoft.CodeAnalysis;
namespace OmniSharp.Extensions
{
public static class ISymbolExtensions
{
private readonly static CachedStringBuilder s_cachedBuilder;
public static string GetMetadataName(this ISymbol symbol)
{
if (symbol == null)
{
throw new ArgumentNullException(nameof(symbol));
}
var symbols = new Stack<ISymbol>();
while (symbol != null)
{
if (symbol.Kind == SymbolKind.Assembly ||
symbol.Kind == SymbolKind.NetModule)
{
break;
}
if ((symbol as INamespaceSymbol)?.IsGlobalNamespace == true)
{
break;
}
symbols.Push(symbol);
symbol = symbol.ContainingSymbol;
}
var builder = s_cachedBuilder.Acquire();
try
{
ISymbol current = null, previous = null;
while (symbols.Count > 0)
{
current = symbols.Pop();
if (previous != null)
{
if (previous.Kind == SymbolKind.NamedType &&
current.Kind == SymbolKind.NamedType)
{
builder.Append('+');
}
else
{
builder.Append('.');
}
}
builder.Append(current.MetadataName);
previous = current;
}
return builder.ToString();
}
finally
{
s_cachedBuilder.Release(builder);
}
}
}
}