【问题标题】:Is there a way to associate XML Tags with blocks of properties?有没有办法将 XML 标签与属性块相关联?
【发布时间】:2014-02-18 18:56:33
【问题描述】:

对于 XMLSerialization,您使用 XML 标签来指示如何在序列化中添加属性/字段。

每个属性都有一个 XML 标记很丑。我理解具有明确性的价值,但它的眼睛很痛苦

我的问题是有一种方法可以做这样的事情,其中​​标签与块相关联?

public class Application : IApplication
{
    [XmlAttribute]
    public string Name { get; set; }
    public string Source { get; set; }

    [XmlElement]
    public string Description { get; set; }
    public string Icon { get; set; }
    public string StoreLink { get; set; }

    [XmlIgnore]
    public string Branch { get; set; }
    public string Version { get; set; }
    public string Build { get; set; }
    public bool IsDebug { get; set; }
    public bool IsX86 { get; set; }

    public override string ToString()
    {
        return Name;
    }
}

【问题讨论】:

    标签: c# xml serialization properties formatting


    【解决方案1】:

    显然你可以这样做......

    [XmlAttribute] public string Version;
    [XmlAttribute] public string Number;
    

    这对眼睛来说更容易一些。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-03-28
      • 2021-03-13
      • 1970-01-01
      • 1970-01-01
      • 2011-02-08
      • 2020-05-17
      • 1970-01-01
      相关资源
      最近更新 更多