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

Add source generator #259

Open
marinasundstrom opened this issue Apr 18, 2022 · 7 comments
Open

Add source generator #259

marinasundstrom opened this issue Apr 18, 2022 · 7 comments

Comments

@marinasundstrom
Copy link

This could be improved further with source generators:

Allowing you to just decorate a partial class like so:

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:

using Ardalis.SmartEnum;

sealed partial class TestEnum : SmartEnum<TestEnum>
{
    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);
    }
}
@ardalis
Copy link
Owner

ardalis commented Apr 18, 2022

I like it. Do you want to create one and make a PR?

@wilsonrivera
Copy link

If nobody have requested to work on this, I'd like to volunteer. I don't know if this is the way to go about it as I'm new to contributing

@ardalis
Copy link
Owner

ardalis commented Aug 5, 2022

Go for it @wilsonrivera

@wilsonrivera
Copy link

A few questions, since I'll be taking #293 too
A) would you rather this to be its own package, something like SmartEnum.SourceGenerator where the user needs to opt-in or,
B) would like it to be implicitly included in the SmartEnum package, the same way is done with System.Text.Json, where the source generator is other package and is just included as an analyzer with the aforementioned package?

If goes for option B, would it be ok to include the attributes in the SmartEnum or would rather they are auto generated too?

@ardalis
Copy link
Owner

ardalis commented Aug 5, 2022

Let's see what it looks like all in one, and if it seems too intrusive we can split it. I'm not sure what it's going to look like, yet, until you implement it, which is why I'm uncertain. Ok?

@wilsonrivera
Copy link

Yeah, sounds good, I'll work on it and get a PR ASAP!

@ardalis
Copy link
Owner

ardalis commented Jan 16, 2024

See also #356

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

No branches or pull requests

3 participants