【发布时间】:2010-12-08 13:06:56
【问题描述】:
人们采取哪些方法(如果有)来管理您班级中的guard clause 爆炸?例如:
public void SomeMethod<T>(string var1, IEnumerable<T> items, int count)
{
if (string.IsNullOrEmpty(var1))
{
throw new ArgumentNullException("var1");
}
if (items == null)
{
throw new ArgumentNullException("items");
}
if (count < 1)
{
throw new ArgumentOutOfRangeException("count");
}
... etc ....
}
在我目前正在处理的项目中,有许多类在公共方法上有一组类似的保护子句。
我知道 .NET 4.0 代码合同,但目前这不是我们团队的选择。
【问题讨论】:
标签: c# validation guard-clause