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

FIX: CS1574: XML comment has cref attribute 'Enum' that could not be resolved #72

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 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
15 changes: 8 additions & 7 deletions Supernova.Enum.Generators/EnumSourceGenerator.cs
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -27,7 +27,7 @@ public void Execute(GeneratorExecutionContext context)
context.AddSource($"{SourceGeneratorHelper.AttributeName}Attribute.g.cs", SourceText.From($@"
using System;
using System.CodeDom.Compiler;
namespace {SourceGeneratorHelper.NameSpace}
namespace Supernova.Enum.Generators
{{
/// <summary>
/// An attribute that marks enums for which extension methods are to be generated.
Expand Down Expand Up @@ -110,7 +110,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.FullNamespace()}
{{
/// <summary>
/// Provides extension methods for operations related to the {symbol.Name} enumeration.
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
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is better to have one extension, not several

Copy link
Contributor Author

@OhFlowi OhFlowi Mar 29, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, it is better to have a single extension file for a single target, especially if you only have a few methods.

But since this new file targets INamespaceSymbol and not ISymbol like the already existing FullName extension, the new file has a reason to exist.

{
/// <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 FullNamespace(this INamespaceSymbol namespaceSymbol, string fullName = null)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this method exist in to SymbolExtensions

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The original FullNamespace extension in the SymbolExtensions file is replaced by the new extension file. The why I already explained in the other comment.

{
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;
}
}
38 changes: 2 additions & 36 deletions Supernova.Enum.Generators/Extensions/SymbolExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis;

namespace Supernova.Enum.Generators.Extensions;

Expand All @@ -14,38 +13,5 @@ public static class SymbolExtensions
/// <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;
}
=> $"{symbol.ContainingNamespace.FullNamespace()}.{symbol.Name}";
}
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