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

The C# compiler get confused with the OutOfRange clauses for Enums and for Structs #139

Closed
rafaelsc opened this issue Oct 24, 2021 · 2 comments

Comments

@rafaelsc
Copy link
Contributor

rafaelsc commented Oct 24, 2021

  • .NET SDK Version: Any
  • GuardClauses Version: 3.2.0

Steps to Reproduce:

  1. Using the current 3.2.0 Nuget Release in a console application
  2. Add this sample code:
private static void TestStruct(int x)
{
	Guard.Against.OutOfRange(x, nameof(x), -10, 10); // OK
	Guard.Against.OutOfRange<int>(x, nameof(x), -10, 10); // Compiler Error: CS1501 No overload for method 'OutOfRange' takes 4 arguments.
}

See this dotnetfiddle https://dotnetfiddle.net/nbXa8U

Recommendation:

  • Rename the 2 OutOfRange clauses for Enums to EnumOutOfRange. To avoid any conflict. And making the naming more mean full when we are dealing with the Enum clauses.
@rafaelsc
Copy link
Contributor Author

With the current main brach codebase, this behavior has changed.

private static void TestStruct(int x)
{
	Guard.Against.OutOfRange(x, nameof(x), -10, 10); // OK
	Guard.Against.OutOfRange<int>(x, nameof(x), -10, 10); // OK
}

But I particularly think the EnumOutOfRange is a better suitable name for the clauses to check Enums.

@rafaelsc
Copy link
Contributor Author

Related #131

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