且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

LINQ to XML-子类化XElement

更新时间:2022-11-27 22:43:54

您应该在这里使用封装而不是继承.

You should use encapsulation, rather than inheritance here.

 class TopLevelBlock
  {
    readonly XElement doc;

    TopLevelBlock(string name)
    {
      doc = new XElement((XName)name);
      doc.SetAttributeValue("someAttribute","");

    }

    public int someAttribute
    {
      get
      {
        return int.Parse(doc.Attribute("someAttribute").Value);
      }
      set
      {
        doc.SetAttributeValue("someAttribute", value.ToString());
      }
    }
  }

也许是XML序列化.

David