ardalis / ardalis/SmartEnum

Add source generator

Open
#259 7 comments 5 reactions 0 assignees View on GitHub
enhancement good first issue help wanted
Dominant language
C#
Stars
2.4k
Forks
184
PR merge metrics
No merged PRs in 30d

Description

This could be improved further with source generators:

Allowing you to just decorate a partial class like so:

```c#
using Ardalis.SmartEnum;

[SmartEnum]
public sealed partial class TestEnum
{
[EnumMember]
public static readonly TestEnum One;

[EnumMember]
public static readonly TestEnum Two;

[EnumMember]
public static readonly TestEnum Three;
}
```

Generated code:

```c#
using Ardalis.SmartEnum;

sealed partial class TestEnum : SmartEnum
{
private TestEnum(string name, int value) : base(name, value)
{
One = new TestEnum(nameof(One), 1);
Two = new TestEnum(nameof(Two), 2);
Three = new TestEnum(nameof(Three), 3);
}
}
```

Contributor guide

Open the contributing guide

Research direction

Start by reading the existing SmartEnum base-class implementation and the proposed partial-class usage in the issue. Define how the [SmartEnum] and [EnumMember] attributes map to generated code, then verify that the generator produces the shown constructor and members for the TestEnum example.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
compilers
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.