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: Fixed CS1591 warnings about missing XML comments #68

Closed
wants to merge 4 commits 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
21 changes: 21 additions & 0 deletions Supernova.Enum.Generators/EnumGeneratorAttributeHelper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
namespace Supernova.Enum.Generators;

public static class EnumGeneratorAttributeHelper
Copy link
Owner

Choose a reason for hiding this comment

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

Was there a special reason that you separated these features from the SourceGeneratorHelper class?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This separation follows the single responsibility principle and helps keep the project organized. Based on the file name, it is now clear what this file does without having to open it.

{
public const string Name = "EnumGenerator";

public const string Content = @"// <auto-generated />

using System;
using System.CodeDom.Compiler;

namespace " + SourceGeneratorHelper.NameSpace + @"
{
[AttributeUsage(AttributeTargets.Enum)]
[GeneratedCodeAttribute(""Supernova.Enum.Generators"", null)]
Copy link
Owner

Choose a reason for hiding this comment

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

Does adding Generated Code Attribute make a special change?

Copy link
Contributor Author

@OhFlowi OhFlowi Mar 10, 2024

Choose a reason for hiding this comment

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

It's a support attribute for tools that use Reflection for analysis. Does the same thing as the auto-generated tag for tools that not uses a Reflection approach.

public sealed class " + Name + @"Attribute : Attribute
{
}
}
";
}
21 changes: 10 additions & 11 deletions Supernova.Enum.Generators/EnumSourceGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,10 @@ public void Execute(GeneratorExecutionContext context)
// Debugger.Launch();
// }
//#endif
context.AddSource($"{SourceGeneratorHelper.AttributeName}Attribute.g.cs", SourceText.From($@"using System;
namespace {SourceGeneratorHelper.NameSpace}
{{
[AttributeUsage(AttributeTargets.Enum)]
public sealed class {SourceGeneratorHelper.AttributeName}Attribute : Attribute
{{
}}
}}
", Encoding.UTF8));

context.AddSource(
$"{EnumGeneratorAttributeHelper.Name}Attribute.g.cs",
SourceText.From(EnumGeneratorAttributeHelper.Content, Encoding.UTF8));

var enums = new List<EnumDeclarationSyntax>();

Expand All @@ -42,7 +37,7 @@ public sealed class {SourceGeneratorHelper.AttributeName}Attribute : Attribute
enums.AddRange(syntaxTree.GetRoot().DescendantNodesAndSelf()
.OfType<EnumDeclarationSyntax>()
.Where(x => semanticModel.GetDeclaredSymbol(x).GetAttributes()
.Any(x => string.Equals(x.AttributeClass.Name, SourceGeneratorHelper.AttributeName,
.Any(x => string.Equals(x.AttributeClass.Name, EnumGeneratorAttributeHelper.Name,
StringComparison.OrdinalIgnoreCase))));
}

Expand Down Expand Up @@ -101,11 +96,15 @@ public sealed class {SourceGeneratorHelper.AttributeName}Attribute : Attribute
}
}

var sourceBuilder = new StringBuilder($@"using System;
var sourceBuilder = new StringBuilder($@"// <auto-generated />

using System;
using System.CodeDom.Compiler;
using System.Collections.Generic;
using System.Collections.Immutable;
namespace {SourceGeneratorHelper.NameSpace}
{{
[GeneratedCodeAttribute(""Supernova.Enum.Generators"", null)]
{symbol.DeclaredAccessibility.ToString("G").ToLower()} static class {symbol.Name}EnumExtensions
{{");

Expand Down
19 changes: 0 additions & 19 deletions Supernova.Enum.Generators/SourceGeneratorHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,7 @@

public static class SourceGeneratorHelper
{
private const string Header = @"//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by the Supernova source generator
// Do not change this file !!
// </auto-generated>
//------------------------------------------------------------------------------
using System;
";

public const string NameSpace = "EnumFastToStringGenerated";
public const string AttributeName = "EnumGenerator";
public const string ExtensionMethodNameToString = "ToStringFast";
public const string ExtensionMethodNameIsDefined = "IsDefinedFast";
public const string ExtensionMethodNameToDisplay = "ToDisplayFast";
Expand All @@ -22,13 +12,4 @@ public static class SourceGeneratorHelper
public const string ExtensionMethodNameGetLength = "GetLengthFast";
public const string PropertyDisplayNamesDictionary = "DisplayNamesDictionary";
public const string PropertyDisplayDescriptionsDictionary = "DisplayDescriptionsDictionary";

public const string Attribute = Header + $@"

namespace {NameSpace};

[AttributeUsage(AttributeTargets.Enum)]
public sealed class {AttributeName}Attribute : System.Attribute
{{
}}";
}