private static void BuildName(NameSyntax nameSyntax, StringBuilder builder, bool includeAlias) { if (nameSyntax.IsKind(SyntaxKind.IdentifierName)) { var identifierNameSyntax = (IdentifierNameSyntax)nameSyntax; builder.Append(identifierNameSyntax.Identifier.ValueText); } else if (nameSyntax.IsKind(SyntaxKind.QualifiedName)) { var qualifiedNameSyntax = (QualifiedNameSyntax)nameSyntax; BuildName(qualifiedNameSyntax.Left, builder, includeAlias); builder.Append(DotChar); BuildName(qualifiedNameSyntax.Right, builder, includeAlias); } else if (nameSyntax.IsKind(SyntaxKind.GenericName)) { var genericNameSyntax = (GenericNameSyntax)nameSyntax; builder.AppendFormat("{0}{1}", genericNameSyntax.Identifier.ValueText, genericNameSyntax.TypeArgumentList.ToString()); } else if (nameSyntax.IsKind(SyntaxKind.AliasQualifiedName)) { var aliasQualifiedNameSyntax = (AliasQualifiedNameSyntax)nameSyntax; if (includeAlias) { builder.Append(aliasQualifiedNameSyntax.Alias.Identifier.ValueText); builder.Append("::"); } builder.Append(aliasQualifiedNameSyntax.Name.Identifier.ValueText); } }
private static bool StartsWithAlias(NameSyntax name) { if (name.IsKind(SyntaxKind.AliasQualifiedName)) { return(true); } if (name is QualifiedNameSyntax qualifiedName) { return(StartsWithAlias(qualifiedName.Left)); } return(false); }