diff --git a/Supernova.Enum.Generators/EnumSourceGenerator.cs b/Supernova.Enum.Generators/EnumSourceGenerator.cs index 7ab0f1a..32aefdc 100644 --- a/Supernova.Enum.Generators/EnumSourceGenerator.cs +++ b/Supernova.Enum.Generators/EnumSourceGenerator.cs @@ -1,11 +1,11 @@ -using Microsoft.CodeAnalysis; -using Microsoft.CodeAnalysis.CSharp.Syntax; -using Microsoft.CodeAnalysis.Text; -using Supernova.Enum.Generators.Extensions; -using System; +using System; using System.Collections.Generic; using System.Linq; using System.Text; +using Microsoft.CodeAnalysis; +using Microsoft.CodeAnalysis.CSharp.Syntax; +using Microsoft.CodeAnalysis.Text; +using Supernova.Enum.Generators.Extensions; namespace Supernova.Enum.Generators; @@ -28,7 +28,7 @@ public void Execute(GeneratorExecutionContext context) $@"// using System; using System.CodeDom.Compiler; -namespace {SourceGeneratorHelper.NameSpace} +namespace Supernova.Enum.Generators {{ /// /// An attribute that marks enums for which extension methods are to be generated. @@ -114,7 +114,8 @@ public sealed class {SourceGeneratorHelper.AttributeName}Attribute : Attribute using System.CodeDom.Compiler; using System.Collections.Generic; using System.Collections.Immutable; -namespace {SourceGeneratorHelper.NameSpace} + +namespace {symbol.ContainingNamespace.FullNamespace()} {{ /// /// Provides extension methods for operations related to the enumeration. diff --git a/Supernova.Enum.Generators/Extensions/NamespaceSymbolExtensions.cs b/Supernova.Enum.Generators/Extensions/NamespaceSymbolExtensions.cs new file mode 100644 index 0000000..4e4565d --- /dev/null +++ b/Supernova.Enum.Generators/Extensions/NamespaceSymbolExtensions.cs @@ -0,0 +1,40 @@ +using System; +using Microsoft.CodeAnalysis; + +namespace Supernova.Enum.Generators.Extensions; + +/// +/// Provides extension methods for objects. +/// +public static class NamespaceSymbolExtensions +{ + /// + /// Gets the full name of the namespace, including parent namespaces. + /// + /// The namespace symbol. + /// Optional. The initial full name to start with. + /// The full name of the namespace. + public static string FullNamespace(this INamespaceSymbol namespaceSymbol, string fullName = null) + { + fullName ??= string.Empty; + + if (namespaceSymbol == null) + { + return fullName; + } + + if (namespaceSymbol.ContainingNamespace != null) + { + fullName = namespaceSymbol.ContainingNamespace.FullNamespace(fullName); + } + + if (!fullName.Equals(string.Empty, StringComparison.OrdinalIgnoreCase)) + { + fullName += "."; + } + + fullName += namespaceSymbol.Name; + + return fullName; + } +} diff --git a/Supernova.Enum.Generators/Extensions/SymbolExtensions.cs b/Supernova.Enum.Generators/Extensions/SymbolExtensions.cs index 18e8861..60714bf 100644 --- a/Supernova.Enum.Generators/Extensions/SymbolExtensions.cs +++ b/Supernova.Enum.Generators/Extensions/SymbolExtensions.cs @@ -1,5 +1,5 @@ -using Microsoft.CodeAnalysis; using System; +using Microsoft.CodeAnalysis; namespace Supernova.Enum.Generators.Extensions; @@ -14,38 +14,5 @@ public static class SymbolExtensions /// The symbol. /// The full name of the symbol. public static string FullName(this ISymbol symbol) - { - // TODO: Use NamespaceSymbolExtensions.FullName after Merge of #70 - return $"{symbol.ContainingNamespace.FullNamespace()}.{symbol.Name}"; - } - - /// - /// Gets the full name of the namespace, including parent namespaces. - /// - /// The namespace symbol. - /// Optional. The initial full name to start with. - /// The full name of the namespace. - 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; - } + => $"{symbol.ContainingNamespace.FullNamespace()}.{symbol.Name}"; } diff --git a/test/Console.Test.Benchmark/Program.cs b/test/Console.Test.Benchmark/Program.cs index da49a6f..fa693fc 100644 --- a/test/Console.Test.Benchmark/Program.cs +++ b/test/Console.Test.Benchmark/Program.cs @@ -8,13 +8,13 @@ using BenchmarkDotNet.Jobs; using BenchmarkDotNet.Order; using BenchmarkDotNet.Running; -using EnumFastToStringGenerated; using Perfolizer.Horology; using System; using System.ComponentModel.DataAnnotations; using System.Linq; using System.Reflection; using System.Text.RegularExpressions; +using Supernova.Enum.Generators; namespace Console.Test.Benchmark; diff --git a/test/UnitTests/EnumGeneratorTest.cs b/test/UnitTests/EnumGeneratorTest.cs index 8b2dc84..8e13649 100644 --- a/test/UnitTests/EnumGeneratorTest.cs +++ b/test/UnitTests/EnumGeneratorTest.cs @@ -1,9 +1,9 @@ -using EnumFastToStringGenerated; -using FluentAssertions; +using FluentAssertions; using Microsoft.VisualStudio.TestTools.UnitTesting; using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; +using Supernova.Enum.Generators; namespace UnitTests; diff --git a/test/UnitTests/InternalEnumGeneratorTest.cs b/test/UnitTests/InternalEnumGeneratorTest.cs index 84a5a5a..01edcb0 100644 --- a/test/UnitTests/InternalEnumGeneratorTest.cs +++ b/test/UnitTests/InternalEnumGeneratorTest.cs @@ -1,9 +1,9 @@ -using EnumFastToStringGenerated; -using FluentAssertions; +using FluentAssertions; using Microsoft.VisualStudio.TestTools.UnitTesting; using System; using System.Collections.Generic; using System.ComponentModel.DataAnnotations; +using Supernova.Enum.Generators; namespace UnitTests;