-
-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #71 from OhFlowi/doc/EnumExtensionMethods
doc: Missing documentation on the generated code added
- Loading branch information
Showing
2 changed files
with
156 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
using System; | ||
using Microsoft.CodeAnalysis; | ||
|
||
namespace Supernova.Enum.Generators.Extensions; | ||
|
||
/// <summary> | ||
/// Provides extension methods for <see cref="ISymbol"/> objects. | ||
/// </summary> | ||
public static class SymbolExtensions | ||
{ | ||
/// <summary> | ||
/// Gets the full name of the symbol, including namespaces. | ||
/// </summary> | ||
/// <param name="symbol">The symbol.</param> | ||
/// <returns>The full name of the symbol.</returns> | ||
public static string FullName(this ISymbol symbol) | ||
{ | ||
// TODO: Use NamespaceSymbolExtensions.FullName after Merge of #70 | ||
return $"{symbol.ContainingNamespace.FullNamespace()}.{symbol.Name}"; | ||
} | ||
|
||
/// <summary> | ||
/// Gets the full name of the namespace, including parent namespaces. | ||
/// </summary> | ||
/// <param name="namespaceSymbol">The namespace symbol.</param> | ||
/// <param name="fullNamespace">Optional. The initial full name to start with.</param> | ||
/// <returns>The full name of the namespace.</returns> | ||
public static string FullNamespace(this INamespaceSymbol namespaceSymbol, string fullNamespace = null) | ||
{ | ||
fullNamespace ??= string.Empty; | ||
|
||
if (namespaceSymbol == null) | ||
{ | ||
return fullNamespace; | ||
} | ||
|
||
if (namespaceSymbol.ContainingNamespace != null) | ||
{ | ||
fullNamespace = namespaceSymbol.ContainingNamespace.FullNamespace(fullNamespace); | ||
} | ||
|
||
if (!fullNamespace.Equals(string.Empty, StringComparison.OrdinalIgnoreCase)) | ||
{ | ||
fullNamespace += "."; | ||
} | ||
|
||
fullNamespace += namespaceSymbol.Name; | ||
|
||
return fullNamespace; | ||
} | ||
} |