请允许我说,我有这些阶层。
public class BaseClass
{
public int Id { get; set; }
}
以及
public class SomeClass : BaseClass
{
... more properties ...
}
基地地图集被认为在许多地方使用。
In my case I m using ASP.NET MVC 3 s EditorForModel to render Views, 以及 it s common to decorate properties with attributes such as [Display(Name = "Id"), Required]
But lets say I would want to decorate the properties of BaseClass in different ways for every class that inherits it. In SomeClass
I may want to decorate Id
with [Required]
以及 in OtherClass
I might want to decorate it with [SomeCustomAttribute]
.
Is there a way to this?
能够做这样的事情是明智的:
public class SomeClass : BaseClass
{
public SomeClass()
{
WithProperty(x => x.Id).AddAttribute(new RequiredAttribute());
...
}
... more properties ...
}