是否可以在派生类中清除DataAnnotations
?
public class User
{
[Required(ErrorMessageResourceType = typeof (UserMessages), ErrorMessageResourceName = "BIRTHDATE_REQUIRED")]
public virtual DateTime BirthDate { get; set; }
}
派生类
public class UserModel : User
{
//i dont want data annotations to be used here
[Clear] - something like this
public override DateTime BirthDate{ get; set; }
}
答案 0 :(得分:1)
是。您可以通过将Inherited设置为false来清除下面指定的派生类的注释。
// This defaults to Inherited = true.
public class MyAttribute : Attribute
{
//...
}
[AttributeUsage(AttributeTargets.Method, Inherited = false)]
public class YourAttribute : Attribute
{
//...
}
请参阅以下链接以获取进一步参考。
http://msdn.microsoft.com/en-us/library/84c42s56.aspx#cpconwritingcustomattributesanchor2