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

Unable to use OutOfRange<T> with decimal types #46

Closed
fingers10 opened this issue Nov 16, 2019 · 5 comments
Closed

Unable to use OutOfRange<T> with decimal types #46

fingers10 opened this issue Nov 16, 2019 · 5 comments

Comments

@fingers10
Copy link

Dear Steve,

I'm not able to use OutOfRange for decimal types like Guard.Against.OutOfRange(unitPrice, nameof(unitPrice), 0, decimal.MaxValue); when I checked the source code, I can see that OutOfRange is marked private. Please can you change that to public? This could help to use it with many types. Correct me if I'm wrong.

Thanks,
Abdul

@KyleMcMaster
Copy link
Contributor

Hello!
Rather than marking the OutOfRange method cited above as public, would it be better to implement another extension method specifically for the Decimal type?

Something like:
public static void OutOfRange(this IGuardClause guardClause, Decimal input, string parameterName, Decimal rangeFrom, Decimal rangeTo)

I can put in a PR for the above if needed. :)

@fingers10
Copy link
Author

@KyleMcMaster what if you need for some other type in future? Instead of keep adding new extension making it public would help right?

@KyleMcMaster
Copy link
Contributor

@fingers10 It appears OutOfRange has been kept private for a reason, as a public implementation of it for int, datetime, and enum types already exists.

@fingers10
Copy link
Author

again what about short or any other types?

@ardalis
Copy link
Owner

ardalis commented Dec 2, 2019

The current pattern followed by other guards as well is to keep the generic helper private and write concrete non-generic public extension methods. I think while this means writing a little more code it provides an opportunity to vary the behavior if needed in the specific extension instead of adding conditional logic to the generic method.

So, I think I’ll keep the generic method private but will take PRs for whatever concrete types are needed.

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