Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BREAKING CHANGE: Changed the namespace of the generated extension met… #70

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions Supernova.Enum.Generators/EnumSourceGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using Microsoft.CodeAnalysis.Text;
using Supernova.Enum.Generators.Extensions;

namespace Supernova.Enum.Generators;

Expand All @@ -24,7 +25,7 @@ public void Execute(GeneratorExecutionContext context)
// }
//#endif
context.AddSource($"{SourceGeneratorHelper.AttributeName}Attribute.g.cs", SourceText.From($@"using System;
namespace {SourceGeneratorHelper.NameSpace}
namespace Supernova.Enum.Generators
{{
[AttributeUsage(AttributeTargets.Enum)]
public sealed class {SourceGeneratorHelper.AttributeName}Attribute : Attribute
Expand Down Expand Up @@ -104,7 +105,8 @@ public sealed class {SourceGeneratorHelper.AttributeName}Attribute : Attribute
var sourceBuilder = new StringBuilder($@"using System;
using System.Collections.Generic;
using System.Collections.Immutable;
namespace {SourceGeneratorHelper.NameSpace}

namespace {symbol.ContainingNamespace.FullName()}
{{
{symbol.DeclaredAccessibility.ToString("G").ToLower()} static class {symbol.Name}EnumExtensions
{{");
Expand Down
40 changes: 40 additions & 0 deletions Supernova.Enum.Generators/Extensions/NamespaceSymbolExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using System;
using Microsoft.CodeAnalysis;

namespace Supernova.Enum.Generators.Extensions;

/// <summary>
/// Provides extension methods for <see cref="INamespaceSymbol"/> objects.
/// </summary>
public static class NamespaceSymbolExtensions
{
/// <summary>
/// Gets the full name of the namespace, including parent namespaces.
/// </summary>
/// <param name="namespaceSymbol">The namespace symbol.</param>
/// <param name="fullName">Optional. The initial full name to start with.</param>
/// <returns>The full name of the namespace.</returns>
public static string FullName(this INamespaceSymbol namespaceSymbol, string fullName = null)
{
fullName ??= string.Empty;

if (namespaceSymbol == null)
{
return fullName;
}

if (namespaceSymbol.ContainingNamespace != null)
{
fullName = namespaceSymbol.ContainingNamespace.FullName(fullName);
}

if (!fullName.Equals(string.Empty, StringComparison.OrdinalIgnoreCase))
{
fullName += ".";
}

fullName += namespaceSymbol.Name;

return fullName;
}
}
2 changes: 1 addition & 1 deletion test/Console.Test.Benchmark/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
4 changes: 2 additions & 2 deletions test/UnitTests/EnumGeneratorTest.cs
Original file line number Diff line number Diff line change
@@ -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;

Expand Down
4 changes: 2 additions & 2 deletions test/UnitTests/InternalEnumGeneratorTest.cs
Original file line number Diff line number Diff line change
@@ -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;

Expand Down