Skip to content

Conversation

licon4812
Copy link

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 new ShortName attribute, generate corresponding extension methods and dictionaries, and add comprehensive tests to validate the functionality.

Linked issues

resolves #138

Enhancements to Enum Source Generator:

  • Added a new dictionary enumShortNames to store short names for enum members and updated the source generator to populate it when the ShortName attribute is provided. (Supernova.Enum.Generators/EnumSourceGenerator.cs: [1] [2]
  • Introduced the ToShortName method to generate extension methods for converting enum values to their short names. (Supernova.Enum.Generators/EnumSourceGenerator.cs: [1] [2]
  • Added the 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:

Test Enhancements:

  • Updated test enums (UserType, UserTypeTest, and InternalUserTypeTest) to include the ShortName attribute for enum members. (test/Console.Test.Benchmark/Program.cs: [1] test/UnitTests/EnumGeneratorTest.cs: [2] test/UnitTests/InternalEnumGeneratorTest.cs: [3]
  • Added unit tests for ToShortNameFast extension method, including cases for undefined values and default values. (test/UnitTests/EnumGeneratorTest.cs: [1] [2]; test/UnitTests/InternalEnumGeneratorTest.cs: [3] [4]
  • Introduced benchmarks for the ToShortNameFast and ToShortNameNative methods to measure performance. (test/Console.Test.Benchmark/Program.cs: [1] [2]

@EngRajabi EngRajabi requested a review from Copilot August 5, 2025 13:09
Copilot

This comment was marked as outdated.

licon4812 and others added 2 commits August 11, 2025 13:30
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@EngRajabi EngRajabi requested a review from Copilot August 11, 2025 08:49
Copy link

@Copilot Copilot AI left a 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 and DisplayShortNamesDictionary 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) &&
Copy link
Preview

Copilot AI Aug 11, 2025

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.

Suggested change
if (namedArgument.Key.Equals("ShortName", StringComparison.OrdinalIgnoreCase) &&
if (namedArgument.Key.Equals(ShortNameKey, StringComparison.OrdinalIgnoreCase) &&

Copilot uses AI. Check for mistakes.

Copy link
Author

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);
Copy link
Preview

Copilot AI Aug 11, 2025

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.

Suggested change
var propValue = attribute.GetType().GetProperty("ShortName")?.GetValue(attribute, null);
var propValue = attribute.GetType().GetProperty(ShortNameProperty)?.GetValue(attribute, null);

Copilot uses AI. Check for mistakes.

Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add ToShortNameFast
1 participant