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

Are you open to a PR for a nullable Name? #490

Open
pdevito3 opened this issue Feb 1, 2024 · 2 comments
Open

Are you open to a PR for a nullable Name? #490

pdevito3 opened this issue Feb 1, 2024 · 2 comments

Comments

@pdevito3
Copy link
Contributor

pdevito3 commented Feb 1, 2024

hey steve, wanted to check if you were open to a PR that would allow for a null name? this could be useful when you want a smart enum to capture a response like not given without jumping through extra hoops externally or adding an empty string in the smart enum. for example:

    public abstract class KnownRace(string name, int value) : SmartEnum<KnownRace>(name, value)
    {
        public static readonly KnownRace White = new WhiteType();
        public static readonly KnownRace BlackOrAfricanAmerican = new BlackOrAfricanAmericanType();
        public static readonly KnownRace NotGiven = new NotGivenType();

        public abstract Guid? LegacyGuid { get; }
        private const string  legacyOtherGuid = "f5b897e4-cdb7-471b-a6d0-f73d399538b2";
        private class WhiteType() : KnownRace("White", 0)
        {
            public override Guid? LegacyGuid => Guid.Parse("113c8858-d971-4335-909d-48e6808d8839");
        }

        private class BlackOrAfricanAmericanType() : KnownRace("Black or African American", 1)
        {
            public override Guid? LegacyGuid => Guid.Parse("ffbb2f4c-9667-40df-bac4-14ab568023a4");
        }

        //....
        private class NotGivenType() : KnownRace(" ", 100)
        {
            public override Guid? LegacyGuid => null;
        }
    }
@ardalis
Copy link
Owner

ardalis commented Feb 2, 2024

I dunno - I don't think I'd want to use a null for that. Why wouldn't you use a string like "Not Given" which is more clear and less likely to cause runtime NullReference exceptions?

@pdevito3
Copy link
Contributor Author

pdevito3 commented Feb 2, 2024

Makes it harder for something like a dropdown where these options would be. If they select nothing, that still gets recognized as an option and can have extension classes off of it.

You could do a 'not given' name instead of that, but it feeds into the gymnastics outside of this workflow. Where you always have to check for that and return nothing, maybe not show that also as on a screen if the business doesn't want that, etc.

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

No branches or pull requests

2 participants