如何为同一元素包含XmlAttributeAttribute和XmlElementAttribute

时间:2018-11-14 13:29:03

标签: c# asp.net

我有两个要排序的元素,这意味着我必须使用XmlElementAttribute。但是当我添加时,我总是收到错误消息。

 [System.Xml.Serialization.XmlAttribute()]
 public string Name
 {
    get
    {
       return this.Name;
    }
    set
    {
       this.Name = value;
    }
  }

  [System.Xml.Serialization.XmlAttribute()]
 public int Age
 {
    get
    {
       return this.Age;
    }
    set
    {
       this. = value;
    }
  }

我希望首先显示姓名,然后显示年龄,所以我尝试了 到XmlElementAttribute(order = ...),但是正如我所说,我一直在出错。 除了一切正常。所以我有什么办法可以同时使用它们而不会出错。

更新

 [System.Xml.Serialization.XmlAttribute()]
 [System.Xml.Serialization.XmlElementAttribute(order = 1)]
 public string Name
 {
    get
    {
      return this.Name;
    }
    set
    {
      this.Name = value;
    }
 }

 [System.Xml.Serialization.XmlAttribute()]
 [System.Xml.Serialization.XmlElementAttribute(order = 2)]
 public int Age
 {
   get
   {
      return this.Age;
   }
   set
   {
      this. = value;
   }
 }

错误:(System.ArgumentNullException:值不能为空)

0 个答案:

没有答案