If you are just starting out on a new project I recommend using https://github.com/adamralph/liteguard instead of conditions. Especially if using in a mobile application, less allocations and better performance. This project is deprecated and needs a new maintainer. Contact me if you want to take over.
MIT License
56
stars
10
forks
source link
ArgumentException and subclasses should provide ParamName property #8
In testing, one can assert that it throws an ArgumentNullException, and also get the name of the invalid argument from exception.ParamName.
But, for ArgumentException, this doesn't work as expected, because exception.ParamName == null. (Unsure whether the same is true for ArgumentOutOfRangeException.)
So: when library throws an ArgumentNullException it passes the paramName argument, but it doesn't do that when throwing ArgumentException.
This makes some testing quite difficult. When one is testing some method which has multiple arguments any of which could be invalid, the ParamName property tells you WHICH ONE was the problem.
I've looked into the source, but I admit I don't understand how the throwing works, and where to make this fix.
If I check for a
null
argument:In testing, one can assert that it throws an
ArgumentNullException
, and also get the name of the invalid argument fromexception.ParamName
.But, for
ArgumentException
, this doesn't work as expected, becauseexception.ParamName == null
. (Unsure whether the same is true forArgumentOutOfRangeException
.)So: when library throws an
ArgumentNullException
it passes theparamName
argument, but it doesn't do that when throwingArgumentException
.This makes some testing quite difficult. When one is testing some method which has multiple arguments any of which could be invalid, the
ParamName
property tells you WHICH ONE was the problem.I've looked into the source, but I admit I don't understand how the throwing works, and where to make this fix.