【问题标题】:DataContractSerializer not serializing one propertyDataContractSerializer 没有序列化一个属性
【发布时间】:2012-01-12 16:45:34
【问题描述】:

当我序列化以下类时,生成的 XML 文件中缺少 ContentPageId XML 元素。

[CollectionDataContract(ItemName = "Widget")]
public sealed class StructurePage : List<Widget>, IEquatable<StructurePage>
{
    [DataMember]
    public int ContentPageId
    {
        get;
        set;
    }

    public StructurePage(){}

    public StructurePage(int pageId)
    {
        this.ContentPageId = pageId;
    }

    public bool Equals(StructurePage other)
    {
        return this.ContentPageId.Equals(other.ContentPageId);
    }
}
  1. 为什么在序列化时会跳过该属性以及如何将其包含为 XML 元素?
  2. 是否可以将其作为 StructurePage 元素的 XML 属性包含在序列化中?正在网上寻找这个,但可以找到任何信息,显然 XmlSerializer 有 XmlAttributeAttribute 属性,但 DataContractSerializer 没有这样的东西。

【问题讨论】:

    标签: c# xml xml-serialization datacontractserializer


    【解决方案1】:

    浏览这篇帖子http://social.msdn.microsoft.com/Forums/eu/wcf/thread/57eb195a-43a9-47fe-8b1a-a9d23feb2df2

    据此

    集合数据协定类不能包含额外的数据成员。

    希望这会有所帮助。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-04-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多