0
擴展類時,是否可以「更改」屬性的值?一些類似下面:在擴展類時擴展/更改屬性的值
public class Mammal
{
[Validation(Required=true, HelpMessage="This is the body shape of a mammal")]
public virtual string BodyShape { get; set; }
}
public class Dog : Mammal
{
[Validation(HelpMessage = "This is the body shape of a dog")]
public override string BodyShape
{
get
{
return base.BodyShape;
}
set
{
base.BodyShape = value;
}
}
}
我希望能夠讀取Dog.BodyShape屬性,並把它作爲必需=真和HelpMessage =「這是狗的體形」。這可能嗎?如果沒有,那麼可以直接在編譯器中添加'元數據'信息到屬性的任何建議的替代方案?
屬性是繼承的,具體取決於AttributeUsage.Inherited屬性的值(http://msdn.microsoft.com/zh-cn/library/tw5zxet9(v=vs.110).aspx) – dugas