예제 #1
0
        public static string GetFullMetadataName(this INamespaceOrTypeSymbol symbol)
        {
            ISymbol s  = symbol;
            var     sb = new StringBuilder(s.MetadataName);

            var last = s;

            s = s.ContainingSymbol;

            if (s == null)
            {
                return(symbol.GetFullName() !);
            }

            while (!IsRootNamespace(s))
            {
                if (s is ITypeSymbol && last is ITypeSymbol)
                {
                    sb.Insert(0, '+');
                }
                else
                {
                    sb.Insert(0, '.');
                }
                sb.Insert(0, s.MetadataName);

                s = s.ContainingSymbol;
            }

            var namedType = symbol as INamedTypeSymbol;

            if (namedType?.TypeArguments.Any() ?? false)
            {
                var genericArgs = namedType.TypeArguments.Select(GetFullMetadataName).JoinBy(",");
                sb.Append($"[{ genericArgs }]");
            }

            return(sb.ToString());
        }
예제 #2
0
        public static string GetFullMetadataName(this INamespaceOrTypeSymbol symbol)
        {
            ISymbol currentSymbol = symbol;
            var     sb            = new StringBuilder(currentSymbol.MetadataName);

            var last = currentSymbol;

            currentSymbol = currentSymbol.ContainingSymbol;

            if (currentSymbol == null)
            {
                return(symbol.GetFullName());
            }

            while (currentSymbol is object && !IsRootNamespace(currentSymbol))
            {
                if (currentSymbol is ITypeSymbol && last is ITypeSymbol)
                {
                    sb.Insert(0, '+');
                }
                else
                {
                    sb.Insert(0, '.');
                }
                sb.Insert(0, currentSymbol.MetadataName);

                currentSymbol = currentSymbol.ContainingSymbol;
            }

            var namedType = symbol as INamedTypeSymbol;

            if (namedType?.TypeArguments.Any() ?? false)
            {
                var genericArgs = string.Join(",", namedType.TypeArguments.Select(GetFullMetadataName));
                sb.Append($"[{ genericArgs }]");
            }

            return(sb.ToString());
        }