I have the following extension method:
public static void ThrowIfArgumentIsNull(this T value, string argument)
where T : class
{
if (value
See also ArgumentNullException and refactoring for a complete solutions along the same lines as the answer.
What about:
public void Save(Category qwerty)
{
ThrowIfArgumentIsNull( () => return qwerty );
qwerty.ThrowIfArgumentIsNull("qwerty");
// ....
}
then define ThrowIfArgumentIsNull as
public static void ThrowIfArgumentIsNull(Expression> test)
{
if (test.Compile()() == null)
{
// take the expression apart to find the name of the argument
}
}
sorry I don't have the time to fill in the detail or provide the full code at present.