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

Value Normalization #22

Closed
etinquis opened this issue Dec 9, 2022 · 3 comments
Closed

Value Normalization #22

etinquis opened this issue Dec 9, 2022 · 3 comments

Comments

@etinquis
Copy link

etinquis commented Dec 9, 2022

Do you have any recommendations on implementing normalization for values, and/or might there be justification for implementing an option to support normalization during construction? Something like

public MyUnit(T value)
{
    this.value = Normalize(value);
    this.Validate();
}

Right now, I'm looking at normalizing string values via trimming (at a minimum). I can't use Validate to modify the value because my value is readonly. I'd also like to use the value via json conversion, but I don't see an obvious way to inject normalization in there.

As another potential example off the top of my head, consider something like a clamped numeric value, where numbers outside a range are accepted but clamped to the bounds of the range.

@etinquis
Copy link
Author

etinquis commented Dec 9, 2022

If you are interested, I wouldn't mind diving in and implementing it. 👍

@zadykian
Copy link

zadykian commented Apr 8, 2023

+1, it would be really useful

@hadashiA
Copy link
Contributor

hadashiA commented Aug 17, 2023

Implemented it in #31.

Note: Support for the API is slightly different from @etinquis 's suggestion.
Since partial method does not support return values, we use the following style:

private partial void Normalize(ref value)
{
    value = Math.Min(value, 9999);
}

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

3 participants