我正在关注Fail Fast委托人。我想知道为了检查我的构造函数参数参数是否有适当的Assertion类是好的做法。创建自定义断言类
例如:
public static class Assertions
{
public static void ParamterIsNotNull(object subject, string paramName = "")
{
if (subject == null) throw new ArgumentNullException(paramName, "Paramter cannot be null");
}
}
,并在使用中:
public class Test
{
public Test(object obj)
{
Assertions.ParamterIsNotNull(obj, "obj");
}
}
是来卸载异常抛出到另一类好的做法,还是不如直接抛出异常的构造函数?