GuardClauses icon indicating copy to clipboard operation
GuardClauses copied to clipboard

[CallerArgumentExpression] parameter should be the last one to allow passing custom message

Open jvmlet opened this issue 1 year ago • 2 comments
trafficstars

See the guards API below :

public static int Negative([JetBrainsNotNull] this IGuardClause guardClause,
            int input,
            [JetBrainsNotNull][JetBrainsInvokerParameterName][CallerArgumentExpression("input")] string? parameterName = null,
            string? message = null){
......
}

If I want to pass custom message I need to pass parameterName as well, which breaks the CallerArgumentExpression functionality.

jvmlet avatar Oct 09 '24 05:10 jvmlet

Good point. Unfortunately a big breaking change but one we can probably absorb into a future version.

ardalis avatar Oct 22 '24 18:10 ardalis

@jvmlet I guess you can pass a custom message without passing parameterName as follows:

Guard.Against.Negative(input, message: "Test message.");

beyzaaydogan avatar Nov 25 '24 19:11 beyzaaydogan