Tag: guard clause

重构保护条款

人们采用什么方法(如果有的话)管理class级中的保护条款爆炸? 例如: public void SomeMethod(string var1, IEnumerable 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代码合同,但目前这不是我们团队的选择。