【发布时间】:2011-02-28 17:48:51
【问题描述】:
我编写了一个自定义操作方法选择器属性,它具有三个bool 属性。三个都是false是无效的。其中至少一个必须是true。当IsValidForRequest 被执行时,我检查其中至少一个是true。但如果没有,我应该抛出哪个异常?
一些相关代码:
public class MyCustomAttribute : ActionMethodSelectorAttribute
{
public bool Prop1 { get; set; }
public bool Prop2 { get; set; }
public bool Prop3 { get; set; }
public MyCustomAttribute()
{
this.Prop1 = true;
this.Prop2 = true;
this.Prop3 = true;
}
public override bool IsValidForRequest(ControllerContext controllerContext, MethodInfo methodInfo)
{
if (controllerContext == null)
{
throw new ArgumentNullException("controllerContext");
}
// at least one of them must be true
if (!this.Prop1 && !this.Prop2 && !this.Prop3)
{
throw new ?????
}
// other codez here
}
}
属性有很好的初始化它们的能力,同时还提供属性值,所以我必须在IsValidForRequest 方法中检查它们。
[MyCustom(Prop1 = false, Prop2 = false, Prop3 = false)]
应该抛出哪个异常?
【问题讨论】:
标签: c# asp.net-mvc exception