Esempio n. 1
0
        /// <summary>
        /// Semantic model merges the symbols, but the compiled form retains multiple namespaces, which (when referenced from C#) need to keep the correct casing.
        /// <seealso cref="DeclarationNodeVisitor.WithDeclarationCasingAsync(VBSyntax.NamespaceBlockSyntax, ISymbol)"/>
        /// <seealso cref="CommonConversions.WithDeclarationCasing(SyntaxToken, ISymbol, string)"/>
        /// </summary>
        private static TypeSyntax WithDeclarationCasing(TypeSyntax syntax, ITypeSymbol typeSymbol)
        {
            var vbType        = SyntaxFactory.ParseTypeName(typeSymbol.ToDisplayString());
            var originalNames = vbType.DescendantNodes().OfType <CSSyntax.IdentifierNameSyntax>()
                                .Select(i => i.ToString()).ToList();

            return(syntax.ReplaceNodes(syntax.DescendantNodes().OfType <CSSyntax.IdentifierNameSyntax>(), (oldNode, n) =>
            {
                var originalName = originalNames.FirstOrDefault(on => string.Equals(@on, oldNode.ToString(), StringComparison.OrdinalIgnoreCase));
                return originalName != null ? SyntaxFactory.IdentifierName(originalName) : oldNode;
            }));
        }
        private string GetFullReturnType(TypeSyntax returnType)
        {
            var fullReturnType = returnType.ToString();
            var node = returnType.DescendantNodes().OfType<IdentifierNameSyntax>().FirstOrDefault();
            Document cl = null;

            var systemTypes = new List<string>()
            {
                "Guid",
                "Guid?"
            };

            if (node != null && systemTypes.All(x => x != node.Identifier.ToString() && x != returnType.ToString()))
            {
                var nameSpace = SymbolFinder.FindDeclarationsAsync(_project, node.Identifier.ValueText, ignoreCase: false).Result.Last().ContainingNamespace.ToString();

                fullReturnType = fullReturnType.Replace(node.Identifier.ToString(), nameSpace + "." + node.Identifier);
            }

            return fullReturnType;
        }