Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / General / July 2006

Tip: Looking for answers? Try searching our database.

XML Serialization, collection with parental links

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Oleg.Ogurok@gmail.com - 30 Jul 2006 21:43 GMT
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.
simida - 31 Jul 2006 03:32 GMT
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 写道:

> Hi there,
>
[quoted text clipped - 40 lines]
> Thanks,
> -Oleg.
Kevin Spencer - 31 Jul 2006 13:15 GMT
Yes, that is what I was recommending as well.

Signature

HTH,

Kevin Spencer
Microsoft MVP
Professional Chicken Magician

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

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 ??:

> Hi there,
>
[quoted text clipped - 40 lines]
> Thanks,
> -Oleg.
Kevin Spencer - 31 Jul 2006 13:15 GMT
> Is there a better implementation?
> 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.

Signature

HTH,

Kevin Spencer
Microsoft MVP
Professional Chicken Magician

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

> Hi there,
>
[quoted text clipped - 40 lines]
> Thanks,
> -Oleg.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.