Replies: 2 comments 10 replies
-
I made a POC here to check if it works. It does seem to achieve the desired outcome! How much of an improvement would it be to not need to put Downsides are this is a .NET 6 feature so need to add a new target and it won't work with the existing targets so it will make the code need |
Beta Was this translation helpful? Give feedback.
-
This feature should work for NetCore3, NetCore31, net5 and net6 when using C#10. Recent I was thinking I'm adding this support to some libs. I didn't tried with GuardClauses or with your POC @stap123. But I imagine we would have a small issue with Guarding with custom messages. Guard.Against.Null(parameter); // will work nicely and pretty.
Guard.Against.Null(parameter, "Null Found"); // this would set the 'parametersName' to the text 'Null Found' not the custom error message
Guard.Against.Null(parameter, message: "Null Found"); // this will probably work I would like to try find more elegant way to apply this new C#10 to GuardClauses |
Beta Was this translation helpful? Give feedback.
-
Hello,
I was looking into the new APIs in .NET 6 and C# 10 and came across this. It allows you to use
ArgumentException.ThrowIfNull()
.It uses this attribute.
Would using this attribute/pattern in the guard methods remove the need for the
nameof(xyz)
part of the call or am I misunderstanding it's use?Beta Was this translation helpful? Give feedback.
All reactions