Skip to content

Conversation

@IliaBrahinets
Copy link
Contributor

@IliaBrahinets IliaBrahinets commented Jan 20, 2025

The following changes have been made in throw helpers:

  • Added CallerArgumentExpressionAttribute to simplify throw assertions (nameof(parameterName) can be omitted in most cases)
  • Added StringSyntaxAttribute for error message templates

@CLAassistant
Copy link

CLAassistant commented Jan 20, 2025

CLA assistant check
All committers have signed the CLA.

@dlemstra
Copy link
Owner

Thanks for your pull request it will probably take a while before I have time to look at this. Only quick thing that I saw was string? message = "Must not be null". I don't want to change the default message for a ArgumentNullException so please restore those two overloads.

@IliaBrahinets
Copy link
Contributor Author

Removed the default value for IfNull message. The are multiple options with overloads:

  1. IfNull([NotNull] object? value, [CallerArgumentExpression(nameof(value))] string? paramName = null, string? message = null)
  2. IfNull([NotNull] object? value, [CallerArgumentExpression(nameof(value))] string? paramName = null) and IfNull([NotNull] object? value, string message, [CallerArgumentExpression(nameof(value))] string? paramName = null)
  3. IfNull([NotNull] object? value, [CallerArgumentExpression(nameof(value))] string? paramName = null) and IfNull([NotNull] object? value, [CallerArgumentExpression(nameof(value))] string? paramName = null, string? message = null)

The third option causes ambiguity for Throw.IfNull(value) call, while the second isn't cosistent in terms of paramName positioning. I decided to implement the first approach for all throw helpers except overloads with message arguments. Awaiting for your feedback on this.

@dlemstra
Copy link
Owner

dlemstra commented Jan 23, 2025

It looks like you did not address that issue yet? Doing new ArgumentNullException(paramName, null) is not the same as new ArgumentNullException(paramName). I also don't mind fixing this myself.

@IliaBrahinets
Copy link
Contributor Author

You are right. Updated to handle null message cases.

Copy link
Owner

@dlemstra dlemstra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this change, looks a lot better. I left a couple comments.

@IliaBrahinets
Copy link
Contributor Author

All comments have been resolved. Ready for review @dlemstra

@dlemstra
Copy link
Owner

dlemstra commented Jan 29, 2025

Will take a look at it this weekend. Thanks for all the fixes.

This was referenced Dec 10, 2025
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

Successfully merging this pull request may close these issues.

3 participants