开发者

Serialization List with object that has in members objects of List

开发者 https://www.devze.com 2023-03-14 07:43 出处:网络
I want to ask, can I serialize something like this: class A { public A a; } A a1 = new A(); A a2 = new A();

I want to ask, can I serialize something like this:

class A
{
public A a;
}

A a1 = new A();
A a2 = new A();

a1.a = a2;
a2.a = a1;

List<A> aList = new List<A>(){a1,a2开发者_开发百科};

I want to serialize aList, does after deserialization a1.a == a2 and a2.a == a1 ??


It's called a circular reference (http://en.wikipedia.org/wiki/Circular_reference) and some serializers allow this. If a serializer serializes objects in-place, the serialized result would be of infinite length.

The serializer would have to serialize the reference to the object, instead of the object contents in-place, by keeping a reference table during serialization.

0

精彩评论

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

关注公众号