-
-
Notifications
You must be signed in to change notification settings - Fork 18
Added ToShortNames and DisplayShortNames dictionary #139
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
base: master
Are you sure you want to change the base?
Conversation
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This pull request adds support for handling "short names" for enum values through a new ShortName
attribute in the Supernova.Enum.Generators
project. The enhancement enables developers to define and access abbreviated representations of enum values alongside existing display names and descriptions.
Key changes include:
- Introduction of short name processing in the enum source generator with dictionary storage and extension methods
- Addition of
ToShortNameFast
extension method andDisplayShortNamesDictionary
property generation - Comprehensive test coverage for the new short name functionality including edge cases
Reviewed Changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.
Show a summary per file
File | Description |
---|---|
Supernova.Enum.Generators/EnumSourceGenerator.cs | Core implementation of short name processing, dictionary generation, and extension method creation |
Supernova.Enum.Generators/SourceGeneratorHelper.cs | Added constants for new extension method and property names |
test/UnitTests/EnumGeneratorTest.cs | Updated test enum with ShortName attributes and added comprehensive unit tests |
test/UnitTests/InternalEnumGeneratorTest.cs | Mirror of public enum tests for internal enum validation |
test/Console.Test.Benchmark/Program.cs | Added performance benchmarks and native implementation for comparison |
@@ -103,7 +105,11 @@ public sealed class {SourceGeneratorHelper.AttributeName}Attribute : Attribute | |||
{ | |||
enumDescriptions.Add(member.Name, description); | |||
} | |||
|
|||
if (namedArgument.Key.Equals("ShortName", StringComparison.OrdinalIgnoreCase) && |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider extracting the string literal "ShortName" into a constant to improve maintainability and avoid potential typos.
if (namedArgument.Key.Equals("ShortName", StringComparison.OrdinalIgnoreCase) && | |
if (namedArgument.Key.Equals(ShortNameKey, StringComparison.OrdinalIgnoreCase) && |
Copilot uses AI. Check for mistakes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This suggestion does not match the rest of the conventions in the if statements around it
.GetCustomAttributes<DisplayAttribute>(false).FirstOrDefault(); | ||
if (attribute == null) | ||
return value.ToString(); | ||
var propValue = attribute.GetType().GetProperty("ShortName")?.GetValue(attribute, null); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider extracting the string literal "ShortName" into a constant to improve maintainability and avoid potential typos.
var propValue = attribute.GetType().GetProperty("ShortName")?.GetValue(attribute, null); | |
var propValue = attribute.GetType().GetProperty(ShortNameProperty)?.GetValue(attribute, null); |
Copilot uses AI. Check for mistakes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This suggestion does not match the conventions of the tests around it
This pull request introduces support for handling "short names" for enum values in the
Supernova.Enum.Generators
project. The changes include updates to the source generator to process a newShortName
attribute, generate corresponding extension methods and dictionaries, and add comprehensive tests to validate the functionality.Linked issues
resolves #138
Enhancements to Enum Source Generator:
enumShortNames
to store short names for enum members and updated the source generator to populate it when theShortName
attribute is provided. (Supernova.Enum.Generators/EnumSourceGenerator.cs
: [1] [2]ToShortName
method to generate extension methods for converting enum values to their short names. (Supernova.Enum.Generators/EnumSourceGenerator.cs
: [1] [2]DisplayShortNamesDictionary
method to generate a dictionary mapping enum values to their short names. (Supernova.Enum.Generators/EnumSourceGenerator.cs
: Supernova.Enum.Generators/EnumSourceGenerator.csR395-R419)Updates to Source Generator Helper:
ToShortNameFast
extension method andDisplayShortNamesDictionary
property. (Supernova.Enum.Generators/SourceGeneratorHelper.cs
: Supernova.Enum.Generators/SourceGeneratorHelper.csR11-R17)Test Enhancements:
UserType
,UserTypeTest
, andInternalUserTypeTest
) to include theShortName
attribute for enum members. (test/Console.Test.Benchmark/Program.cs
: [1]test/UnitTests/EnumGeneratorTest.cs
: [2]test/UnitTests/InternalEnumGeneratorTest.cs
: [3]ToShortNameFast
extension method, including cases for undefined values and default values. (test/UnitTests/EnumGeneratorTest.cs
: [1] [2];test/UnitTests/InternalEnumGeneratorTest.cs
: [3] [4]ToShortNameFast
andToShortNameNative
methods to measure performance. (test/Console.Test.Benchmark/Program.cs
: [1] [2]