Is it possible for a subclass to override the attributes of the base class?
For example in in asp mvc,
public class BaseModel
{
[Display开发者_开发技巧Name("Such a pretty name")]
public virtual String TheName {get;set;}
}
public class SubModel : BaseModel
{
[DisplayName("An even prettier name!")]
public override string TheName {get;set;}
}
With the above would it be possible to get the Views that use SubModel to make use of its display name attribute and not the base model's?
When I pass submodel to a view, the label isn't using either of the displayname attributes, just the property name.
Take a look at AttributeUsage. IT should allow you to limit the scope of the attributes in your base class.
[AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = false)]
public class BaseClass
精彩评论