Esempio n. 1
0
        private static bool TryGetNamespaceString(INamespaceOrTypeSymbol namespaceSymbol, CompilationUnitSyntax root, bool fullyQualify, string alias, out string namespaceString)
        {
            namespaceString = fullyQualify
                    ? namespaceSymbol.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat)
                    : namespaceSymbol.ToDisplayString();

            if (alias != null)
            {
                namespaceString = alias + "::" + namespaceString;
            }

            return(ShouldAddUsing(namespaceString, root));
        }
Esempio n. 2
0
        public static string GetFullName(this INamespaceOrTypeSymbol type)
        {
            IArrayTypeSymbol arrayType = type as IArrayTypeSymbol;

            if (arrayType != null)
            {
                return($"{arrayType.ElementType.GetFullName()}[]");
            }

            ITypeSymbol t;

            if ((type as ITypeSymbol).IsNullable(out t))
            {
                return($"System.Nullable`1[{t.GetFullName()}]");
            }

            var name = type.ToDisplayString();

            string output;

            if (_fullNamesMaping.TryGetValue(name, out output))
            {
                output = name;
            }

            return(output);
        }
Esempio n. 3
0
        protected override string TryGetDescription(
            INamespaceOrTypeSymbol namespaceOrTypeSymbol,
            SemanticModel semanticModel,
            SyntaxNode contextNode, bool checkForExistingUsing)
        {
            var root = GetCompilationUnitSyntaxNode(contextNode);

            // See if this is a reference to a type from a reference that has a specific alias
            // associated with it.  If that extern alias hasn't already been brought into scope
            // then add that one.
            var externAlias = TryGetExternAliasDirective(
                namespaceOrTypeSymbol, semanticModel, contextNode,
                checkForExistingExternAlias: true);

            if (externAlias != null)
            {
                return($"extern alias {externAlias.Identifier.ValueText};");
            }

            var usingDirective = TryGetUsingDirective(
                namespaceOrTypeSymbol, semanticModel, root, contextNode);

            if (usingDirective != null)
            {
                var displayString = namespaceOrTypeSymbol.ToDisplayString();
                return(namespaceOrTypeSymbol.IsKind(SymbolKind.Namespace)
                    ? $"using {displayString};"
                    : $"using static {displayString};");
            }

            return(null);
        }
        private string GetUsingDirectiveString(INamespaceOrTypeSymbol namespaceOrTypeSymbol)
        {
            var displayString = namespaceOrTypeSymbol.ToDisplayString();

            return(namespaceOrTypeSymbol.IsKind(SymbolKind.Namespace)
                ? $"using {displayString};"
                : $"using static {displayString};");
        }
Esempio n. 5
0
 private static NameSyntax GenerateName(INamespaceOrTypeSymbol symbol)
 {
     if (symbol is ITypeSymbol)
     {
         return(((ITypeSymbol)symbol).GenerateTypeSyntax() as NameSyntax);
     }
     else
     {
         return(SyntaxFactory.ParseName(symbol.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat)));
     }
 }
Esempio n. 6
0
        private static bool TryGetNamespaceString(
            INamespaceOrTypeSymbol namespaceSymbol, CompilationUnitSyntax root, bool fullyQualify, string alias,
            bool checkForExistingUsing, out string namespaceString)
        {
            if (namespaceSymbol is ITypeSymbol)
            {
                namespaceString = null;
                return(false);
            }

            namespaceString = fullyQualify
                    ? namespaceSymbol.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat)
                    : namespaceSymbol.ToDisplayString();

            if (alias != null)
            {
                namespaceString = alias + "::" + namespaceString;
            }

            return(checkForExistingUsing
                ? ShouldAddUsing(namespaceString, root)
                : true);
        }
Esempio n. 7
0
        private static string FormatNamespaceOrTypeSymbol(INamespaceOrTypeSymbol symbol)
        {
            var displayString = symbol.ToDisplayString(TypeFormat);

            if (symbol is ITypeSymbol type && type.OriginalDefinition.SpecialType == SpecialType.System_Nullable_T)
            {
                return("System.Nullable`1");
            }

            if (symbol.GetTypeArguments().Any())
            {
                return($"{displayString}`{symbol.GetTypeArguments().Length}");
            }

            return(displayString);
        }
Esempio n. 8
0
        public static string?GetFullName(this INamespaceOrTypeSymbol?type)
        {
            if (type is IArrayTypeSymbol arrayType)
            {
                return($"{arrayType.ElementType.GetFullName()}[]");
            }

            if (type is ITypeSymbol ts && ts.IsNullable(out var t))
            {
                return($"System.Nullable`1[{t.GetFullName()}]");
            }

            var name = type?.ToDisplayString();

            return(_fullNamesMaping.UnoGetValueOrDefault(name !, name));
        }
        private string FormatTypeOrNamespace(INamespaceOrTypeSymbol symbol)
        {
            var displayString = symbol.ToDisplayString(TypeFormat);

            var type = symbol as ITypeSymbol;

            if (type != null && type.OriginalDefinition.SpecialType == SpecialType.System_Nullable_T)
            {
                return("System.Nullable`1");
            }

            if (symbol.GetTypeArguments().Any())
            {
                return(string.Format("{0}`{1}", displayString, symbol.GetTypeArguments().Length));
            }

            return(displayString);
        }
Esempio n. 10
0
        public static string GetFullName(this INamespaceOrTypeSymbol type)
        {
            IArrayTypeSymbol arrayType = type as IArrayTypeSymbol;

            if (arrayType != null)
            {
                return($"{arrayType.ElementType.GetFullName()}[]");
            }

            ITypeSymbol t;

            if ((type as ITypeSymbol).IsNullable(out t))
            {
                return($"System.Nullable`1[{t.GetFullName()}]");
            }

            var name = type.ToDisplayString();

            return(_fullNamesMaping.UnoGetValueOrDefault(name, name));
        }
Esempio n. 11
0
        public static string GetFullName(this INamespaceOrTypeSymbol type)
        {
            if (type is IArrayTypeSymbol arrayType)
            {
                return($"{arrayType.ElementType.GetFullName()}[]");
            }

            if ((type as ITypeSymbol).IsNullable(out ITypeSymbol t))
            {
                return($"System.Nullable`1[{t.GetFullName()}]");
            }

            var name = type.ToDisplayString();

            if (!builtinTypeMapping.TryGetValue(name, out string output))
            {
                output = name;
            }

            return(output);
        }
Esempio n. 12
0
 public static string GetShortName(this INamespaceOrTypeSymbol symbol)
 {
     return(symbol.ToDisplayString(ShortNameFormat));
 }
Esempio n. 13
0
 private static NameSyntax GenerateName(INamespaceOrTypeSymbol symbol)
 {
     if (symbol is ITypeSymbol)
     {
         return ((ITypeSymbol)symbol).GenerateTypeSyntax() as NameSyntax;
     }
     else
     {
         return SyntaxFactory.ParseName(symbol.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat));
     }
 }
 public static string GetShortName(this INamespaceOrTypeSymbol symbol)
 => symbol.ToDisplayString(s_shortNameFormat);
        private string FormatTypeOrNamespace(INamespaceOrTypeSymbol symbol)
        {
            var displayString = symbol.ToDisplayString(TypeFormat);

            var type = symbol as ITypeSymbol;
            if (type != null && type.OriginalDefinition.SpecialType == SpecialType.System_Nullable_T)
            {
                return "System.Nullable`1";
            }

            if (symbol.GetTypeArguments().Any())
            {
                return string.Format("{0}`{1}", displayString, symbol.GetTypeArguments().Length);
            }

            return displayString;
        }
        private static bool TryGetStaticNamespaceString(INamespaceOrTypeSymbol namespaceSymbol, CompilationUnitSyntax root, bool fullyQualify, string alias, out string namespaceString)
        {
            if (namespaceSymbol is INamespaceSymbol)
            {
                namespaceString = null;
                return false;
            }

            namespaceString = fullyQualify
                    ? namespaceSymbol.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat)
                    : namespaceSymbol.ToDisplayString();

            if (alias != null)
            {
                namespaceString = alias + "::" + namespaceString;
            }

            return ShouldAddStaticUsing(namespaceString, root);
        }
		private static IList<string> GetNameParts(INamespaceOrTypeSymbol symbol)
		{
			return symbol.ToDisplayString(MonoDevelop.Ide.TypeSystem.Ambience.NameFormat).Split('.');
		}
Esempio n. 18
0
 private static IList <string> GetNameParts(INamespaceOrTypeSymbol symbol)
 {
     return(symbol.ToDisplayString(MonoDevelop.Ide.TypeSystem.Ambience.NameFormat).Split('.'));
 }
 public static string GetFullName(this INamespaceOrTypeSymbol namespaceOrTypeSymbol)
 {
     return(namespaceOrTypeSymbol.ToDisplayString(SymbolDisplayFormat.FullyQualifiedFormat));
 }