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

Suggestion - DefaultValue #599

Open
Aragas opened this issue May 21, 2024 · 0 comments
Open

Suggestion - DefaultValue #599

Aragas opened this issue May 21, 2024 · 0 comments
Labels
enhancement New feature or request

Comments

@Aragas
Copy link

Aragas commented May 21, 2024

Describe the feature

In my real life scenarios I have a concept of DefaultValue - it's mostly used in my custom TryParse scenarios, when the parsing failed, but the value still needs to be valid an initialized with something meaningful.
A possible implementation would be to have a static property DefaultValue, this way we also should be able to use with Static Abstract Members if needed for custom solutions.
The only note I have, since not every type has a default value, it would make sense to have a separate interface IVogenHasDefaultValue<>

[ValueObject<byte>]
[Instance("None", "0")]
public readonly partial record struct TenantId
{
    // Either manually or via Instance
    //public static readonly byte None = From(0);

    public static byte DefaultValue => None;
    // ...
    // Generated Code
    public static global::System.Boolean TryParse(global::System.ReadOnlySpan<byte> utf8Text, 
#if NETCOREAPP3_0_OR_GREATER
[global::System.Diagnostics.CodeAnalysis.NotNullWhen(true)]
#endif
 out TenantId result) {
        if(System.Byte.TryParse(utf8Text, out var __v)) {
            
            
            result = new TenantId(__v);
            return true;
        }

        result = DefaultValue; // instead of `= default`;
        return false;
    }
}
@Aragas Aragas added the enhancement New feature or request label May 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant