开发者

C# Partial deserialization

So I have an x开发者_JAVA百科ml 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>

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?

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

Thanks!


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
}

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


Are you talking about deserializing the xml as it is parsed so that you don't have to load the entire xml file into memory, or deserializing it as you try to access the concrete object?

It might help to look at an implementation of SAX as opposed to DOM:

http://www.saxproject.org/

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜