How do I add an attribute to the field of the base class from child class?

拈花ヽ惹草 提交于 2019-12-10 17:02:28

问题


Base class:

public class XmlNameValueField : XmlBaseField
{                       
        [XmlAttribute("n")]
        [Required]
        public string Name { get; set; }

        [XmlText]
        public string Value { get; set; }        
 }

Child Class:

 public class DateField : XmlNameValueField
 {            
 }

In the Child class field Name must have an additional attribute

[DataType (DataType.EmailAddress)]

回答1:


You'll need to mark the property as virtual in the base class, override it in the child class and add the attributes.



来源:https://stackoverflow.com/questions/7851069/how-do-i-add-an-attribute-to-the-field-of-the-base-class-from-child-class

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!