Skip to content

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

@rafaelsc

Description

@rafaelsc
  • .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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions