SteveDunn / Vogen

A semi-opinionated library which is a source generator and a code analyser. It Source generates Value Objects
Apache License 2.0
888 stars 46 forks source link

List of accepted values #698

Closed MatteoZampariniDev closed 2 weeks ago

MatteoZampariniDev commented 2 weeks ago

Describe the feature

Is it possible to add a source generated method/property that returns a collection of all defined [Instance] values?

[ValueObject<string>] 
[Instance("Pdf", "pdf")]
[Instance("Txt", "txt")]
public readonly partial struct StoredFileType
{
    public static Validation Validate(string value) =>
        GetAllValues().Any(x => x.Value == value) ? Validation.Ok : Validation.Invalid("Invalid value");

    public static StoredFileType[] GetAllValues() => 
        [
            StoredFileType.Pdf, StoredFileType.Txt // source generation?
        ];
}

Thank you

SteveDunn commented 2 weeks ago

Describe the feature

Is it possible to add a source generated method/property that returns a collection of all defined [Instance] values?

[ValueObject<string>] 
[Instance("Pdf", "pdf")]
[Instance("Txt", "txt")]
public readonly partial struct StoredFileType
{
    public static Validation Validate(string value) =>
        GetAllValues().Any(x => x.Value == value) ? Validation.Ok : Validation.Invalid("Invalid value");

    public static StoredFileType[] GetAllValues() => 
        [
            StoredFileType.Pdf, StoredFileType.Txt // source generation?
        ];
}

Thank you

Hi, thanks for the feedback. Have a look at https://github.com/SteveDunn/Intellenum

MatteoZampariniDev commented 2 weeks ago

Thank you

SteveDunn commented 2 weeks ago

Thank you

Very welcome, let me know if this suits your needs. Any feedback on Intellenum greatly appreciated too!