如何添加一个属性从子类的基类的领域? [英] How do I add an attribute to the field of the base class from child class?

查看:119
本文介绍了如何添加一个属性从子类的基类的领域?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

的基类:

 公共类XmlNameValueField:XmlBaseField
{
        [XmlAttribute(n个)]
        [需要]
        公共字符串名称{;组; }

        [XMLTEXT]
        公共字符串值{获得;组; }
 }
 

子类:

 公共类的DateField:XmlNameValueField
 {
 }
 

在子类的字段名称必须有一个附加属性。

  [数据类型(DataType.EmailAddress)
 

解决方案

您将需要标记属性作为虚拟的基类,覆盖它的子类,并添加属性。

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)]

解决方案

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

这篇关于如何添加一个属性从子类的基类的领域?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆