正在重构一些代码:
FooResult Foo(FooArgs args) { ... }使用以下结构检查空值:
if (parameter1 == null)
throw new ArgumentNullException(“parameter1”);
if (parameter... == null)
throw new ArgumentNullException(“parameter...”);
if (parameterN == null)
throw new ArgumentNullException(“parameterN”);ArgumentNullException属性数:
if (args.Property1 == null)
throw new ArgumentNullException(“args.Property1”);
if (args.Property... == null)
throw new ArgumentNullException(“args.Property...”);
if (args.PropertyN == null)
throw new ArgumentNullException(“args.PropertyN”);或者ArgumentExceptionFooArgs参数:
if (args.Property1 == null)
throw new ArgumentException(“Property1 cannot be null.”, “args”);
if (args.Property... == null)
throw new ArgumentException(“Property... cannot be null.”, “args”);
if (args.PropertyN == null)
throw new ArgumentException(“Property2 cannot be null.”, “args”);相似问题