Help | Site Map
Connecting Tech Pros Worldwide
 
 
LinkBack Thread Tools
  #1  
Old July 30th, 2006, 09:35 PM
Oleg.Ogurok@gmail.com
Guest
 
Posts: n/a
Default XML Serialization, collection with parental links

Hi there,

I'm writing a custom collection, which will be referened within a
class. Each item within the collection needs to have a link to the
parent container class, e.g.

Item x;
Container c = x.ParentContainer;

I basically got the idea from ControlCollection class, where each
control has a reference to its parent control.
So far, I've implemented it as follows.

class Container
{
public ItemCollection Items { get; }
}

class ItemCollection
{
public ItemCollection(Container container) { .. }
public void Add(Item item) { _innerCollection.Add(item);
item.SetContainer(_container); }
}

class Item
{
// gets the reference to the parent container
public Container ParentContainer { get; }
}

I need to be able to serialize the Container class and all its members
into XML, and then deserialize it. Upon deserialization, I'm able to
get the values back into the collection. However, the links to the
parent container are not preserved.
I've read that .NET XML serializer doesn't work with circular
references. Perhaps this could be the reason.

Is there a better implementation?
If not, is there a way to relink the parent elements manually upon
deserialization?

Thanks,
-Oleg.

  #2  
Old July 31st, 2006, 03:25 AM
simida
Guest
 
Posts: n/a
Default Re: XML Serialization, collection with parental links

i don't how to relink the parent elements upon deserailization. but i
think after deserailzation process , you can manually use this to
relink relation.

Class Continer
{
public void Relink()
{
foreach (Item item in this.Items)
{
item.SetContainer(this);
}
}
}

Sincerely,
simida

Oleg.Ogurok@gmail.com 写道:
Quote:
Hi there,
>
I'm writing a custom collection, which will be referened within a
class. Each item within the collection needs to have a link to the
parent container class, e.g.
>
Item x;
Container c = x.ParentContainer;
>
I basically got the idea from ControlCollection class, where each
control has a reference to its parent control.
So far, I've implemented it as follows.
>
class Container
{
public ItemCollection Items { get; }
}
>
class ItemCollection
{
public ItemCollection(Container container) { .. }
public void Add(Item item) { _innerCollection.Add(item);
item.SetContainer(_container); }
}
>
class Item
{
// gets the reference to the parent container
public Container ParentContainer { get; }
}
>
I need to be able to serialize the Container class and all its members
into XML, and then deserialize it. Upon deserialization, I'm able to
get the values back into the collection. However, the links to the
parent container are not preserved.
I've read that .NET XML serializer doesn't work with circular
references. Perhaps this could be the reason.
>
Is there a better implementation?
If not, is there a way to relink the parent elements manually upon
deserialization?

Thanks,
-Oleg.
  #3  
Old July 31st, 2006, 01:15 PM
Kevin Spencer
Guest
 
Posts: n/a
Default Re: XML Serialization, collection with parental links

Is there a better implementation?
Quote:
If not, is there a way to relink the parent elements manually upon
deserialization?
Sure, just wire them back up after deserialization, using the parent.

--
HTH,

Kevin Spencer
Microsoft MVP
Professional Chicken Magician

A man, a plan, a canal.
a palindrome that has gone to s**t.


<Oleg.Ogurok@gmail.comwrote in message
news:1154292187.918167.187680@m73g2000cwd.googlegr oups.com...
Quote:
Hi there,
>
I'm writing a custom collection, which will be referened within a
class. Each item within the collection needs to have a link to the
parent container class, e.g.
>
Item x;
Container c = x.ParentContainer;
>
I basically got the idea from ControlCollection class, where each
control has a reference to its parent control.
So far, I've implemented it as follows.
>
class Container
{
public ItemCollection Items { get; }
}
>
class ItemCollection
{
public ItemCollection(Container container) { .. }
public void Add(Item item) { _innerCollection.Add(item);
item.SetContainer(_container); }
}
>
class Item
{
// gets the reference to the parent container
public Container ParentContainer { get; }
}
>
I need to be able to serialize the Container class and all its members
into XML, and then deserialize it. Upon deserialization, I'm able to
get the values back into the collection. However, the links to the
parent container are not preserved.
I've read that .NET XML serializer doesn't work with circular
references. Perhaps this could be the reason.
>
Is there a better implementation?
If not, is there a way to relink the parent elements manually upon
deserialization?
>
Thanks,
-Oleg.
>

  #4  
Old July 31st, 2006, 01:15 PM
Kevin Spencer
Guest
 
Posts: n/a
Default Re: XML Serialization, collection with parental links

Yes, that is what I was recommending as well.

--
HTH,

Kevin Spencer
Microsoft MVP
Professional Chicken Magician

A man, a plan, a canal.
a palindrome that has gone to s**t.


"simida" <youchangping@gmail.comwrote in message
news:1154313133.123459.80670@s13g2000cwa.googlegro ups.com...
i don't how to relink the parent elements upon deserailization. but i
think after deserailzation process , you can manually use this to
relink relation.

Class Continer
{
public void Relink()
{
foreach (Item item in this.Items)
{
item.SetContainer(this);
}
}
}

Sincerely,
simida

Oleg.Ogurok@gmail.com ??:
Quote:
Hi there,
>
I'm writing a custom collection, which will be referened within a
class. Each item within the collection needs to have a link to the
parent container class, e.g.
>
Item x;
Container c = x.ParentContainer;
>
I basically got the idea from ControlCollection class, where each
control has a reference to its parent control.
So far, I've implemented it as follows.
>
class Container
{
public ItemCollection Items { get; }
}
>
class ItemCollection
{
public ItemCollection(Container container) { .. }
public void Add(Item item) { _innerCollection.Add(item);
item.SetContainer(_container); }
}
>
class Item
{
// gets the reference to the parent container
public Container ParentContainer { get; }
}
>
I need to be able to serialize the Container class and all its members
into XML, and then deserialize it. Upon deserialization, I'm able to
get the values back into the collection. However, the links to the
parent container are not preserved.
I've read that .NET XML serializer doesn't work with circular
references. Perhaps this could be the reason.
>
Is there a better implementation?
If not, is there a way to relink the parent elements manually upon
deserialization?
>
Thanks,
-Oleg.

 

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles