1

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; }
}
4

1 回答 1

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

于 2013-04-26T10:52:11.367 回答