C#部分反序列化 [英] C# Partial deserialization

查看:150
本文介绍了C#部分反序列化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我有一个具有相似的结构,以这样的一个XML:

So I have an xml that has a similar structure to this:

<MyObject>
    <PropertyA>Value</PropertyA>
    <PropertyB>Value</PropertyB>
    <PropertyC>Value</PropertyC>
    <ArrayOfOtherObject>
        <OtherObject>
            <PropertyX>Value</PropertyX>
            <PropertyY>Value</PropertyY>
            <PropertyZ>Value</PropertyZ>
        </OtherObject>
        <OtherObject>
            <PropertyX>Value</PropertyX>
            <PropertyY>Value</PropertyY>
            <PropertyZ>Value</PropertyZ>
        </OtherObject>
        <OtherObject>
            <PropertyX>Value</PropertyX>
            <PropertyY>Value</PropertyY>
            <PropertyZ>Value</PropertyZ>
        </OtherObject>
    </ArrayOfOtherObject>
</MyObject>



有没有我可以反序列化MyObject来,但不是ArrayOfOtherObject的方法吗?再后来就做ArrayOfOtherObject的延迟加载需要的时候?

Is there a way that I can deserialize MyObject but not the ArrayOfOtherObject? And then later on do a lazy load of ArrayOfOtherObject when needed?

我通常使用XmlDeserialization,但据我所知它总是加载整个事情。

I usually use XmlDeserialization, but AFAIK it always loads the whole thing.

感谢

推荐答案

您可以使用它由二进制反序列化功能识别特殊的构造>

You can use special constructor which is recognized by binary deserialization functionality:

protected MyObject(SerializationInfo info, StreamingContext context)
{
//here some elements you can load right now, and some other to store in so-to-say string in order to load later
}

在XML的情况下 - 这里是自定义序列化的一个例子:
http://geekswithblogs.net/marcel/archive/2006/05/19/78989.aspx

In case of XML - here is an example of custom serialization: http://geekswithblogs.net/marcel/archive/2006/05/19/78989.aspx

这篇关于C#部分反序列化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆