XmlSerializer 属性反序列化顺序

发布于 2024-08-20 11:22:34 字数 711 浏览 2 评论 0原文

只是想知道是否有人知道 XmlSerializer 如何确定反序列化任何给定对象属性的顺序。

添加信息:

我有一个这样的类:

    private bool _hasGaps = false;
    public bool HasGaps
    {
        get { return _hasGaps; }
        set
        {
            _hasGaps = value;
        }
    }

    private List<GapInfo> _gaps;
    public List<GapInfo> Gaps
    {
        get { return _gaps; }
        set
        {
            _gaps = value;
        }
    }

我在 Gaps setter 和 HasGaps setter 中设置了一个断点,Gaps 首先被反序列化。

更多信息

XML 如下所示:

<Tube Id="3df08765-c4e7-4a87-a0ed-ec76169b47af" Name="Tube">
  <HasGaps>false</HasGaps>
  <Gaps />
</Tube>

Just wondering if anyone knows how the XmlSerializer determines the order for deserializing any given object's properties.

Added info:

I have a class like this:

    private bool _hasGaps = false;
    public bool HasGaps
    {
        get { return _hasGaps; }
        set
        {
            _hasGaps = value;
        }
    }

    private List<GapInfo> _gaps;
    public List<GapInfo> Gaps
    {
        get { return _gaps; }
        set
        {
            _gaps = value;
        }
    }

I set a breakpoint in both Gaps setter and HasGaps setter, Gaps gets deserialized first.

More info

Here's what the XML looks like:

<Tube Id="3df08765-c4e7-4a87-a0ed-ec76169b47af" Name="Tube">
  <HasGaps>false</HasGaps>
  <Gaps />
</Tube>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

趁年轻赶紧闹 2024-08-27 11:22:34

它按照它们在类中出现的顺序对它们进行反序列化。

您是否有理由相信它可能使用不同的顺序?

It deserializes them in the order they appear in the class.

Did you have reason to believe it might use a different order?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文