PC Review


Reply
Thread Tools Rate Thread

array, xmlserializer and inheritance

 
 
Smola
Guest
Posts: n/a
 
      25th Jan 2005


Hi all,


I have a situation like this:


abstract class A
{
public ArrayList List;
// This list will contain objects of derived classes - like B
}

class B : A
{

}


I need to serialize class B with XmlSerializer but in the class A i
cannot define what type will go in the List (with XmlArrayItem) because
the class is abstract and I don't know what types can be derived from
it.

How can I define this in the class B? Is this approach ok:

class B : A
{
[XmlArray, XmlArrayItem (Type = typeof(B))
new public ArrayList List;
}



Thanks.

--
That's me favorite shirt. That's me only shirt!
 
Reply With Quote
 
 
 
 
Matt Berther
Guest
Posts: n/a
 
      25th Jan 2005
Hello Smola,

Im not sure your object model makes sense...

You want a class to maintain a list of instances of that class? How do you
know which one is the main class? This is very similar to the Registry pattern
from PoEAA, and in that pattern you have a separate class that handles the
registry of objects.

Once you do that, the serialization should just fall into place...

--
Matt Berther
http://www.mattberther.com

> Hi all,
>
> I have a situation like this:
>
> abstract class A
> {
> public ArrayList List;
> // This list will contain objects of derived classes - like B
> }
> class B : A
> {
> }
>
> I need to serialize class B with XmlSerializer but in the class A i
> cannot define what type will go in the List (with XmlArrayItem)
> because the class is abstract and I don't know what types can be
> derived from it.
>
> How can I define this in the class B? Is this approach ok:
>
> class B : A
> {
> [XmlArray, XmlArrayItem (Type = typeof(B))
> new public ArrayList List;
> }
> Thanks.
>



 
Reply With Quote
 
Smola
Guest
Posts: n/a
 
      26th Jan 2005
In article <(E-Mail Removed)>,
(E-Mail Removed) says...
> Hello Smola,
>
> Im not sure your object model makes sense...
>
> You want a class to maintain a list of instances of that class?


I want to have an object of the class Node and a list of its child nodes
in the ArrayList, ok?




> > Hi all,
> >
> > I have a situation like this:
> >
> > abstract class A
> > {
> > public ArrayList List;
> > // This list will contain objects of derived classes - like B
> > }
> > class B : A
> > {
> > }
> >
> > I need to serialize class B with XmlSerializer but in the class A i
> > cannot define what type will go in the List (with XmlArrayItem)
> > because the class is abstract and I don't know what types can be
> > derived from it.
> >
> > How can I define this in the class B? Is this approach ok:
> >
> > class B : A
> > {
> > [XmlArray, XmlArrayItem (Type = typeof(B))
> > new public ArrayList List;
> > }
> > Thanks.
> >

>
>
>


--
That's me favorite shirt. That's me only shirt!
 
Reply With Quote
 
Nicole Schenk
Guest
Posts: n/a
 
      5th Feb 2005
Smola wrote:

> In article <(E-Mail Removed)>,
> (E-Mail Removed) says...
>> Hello Smola,
>>
>> Im not sure your object model makes sense...
>>
>> You want a class to maintain a list of instances of that class?

>
> I want to have an object of the class Node and a list of its child nodes
> in the ArrayList, ok?
>
>
>
>
>> > Hi all,
>> >
>> > I have a situation like this:
>> >
>> > abstract class A
>> > {
>> > public ArrayList List;
>> > // This list will contain objects of derived classes - like B
>> > }
>> > class B : A
>> > {
>> > }
>> >
>> > I need to serialize class B with XmlSerializer but in the class A i
>> > cannot define what type will go in the List (with XmlArrayItem)
>> > because the class is abstract and I don't know what types can be
>> > derived from it.
>> >
>> > How can I define this in the class B? Is this approach ok:
>> >
>> > class B : A
>> > {
>> > [XmlArray, XmlArrayItem (Type = typeof(B))
>> > new public ArrayList List;
>> > }
>> > Thanks.
>> >

>>
>>
>>

>

Perfecly reasonable, and I don't know the solution either.
Thanks
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

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 On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to serialize a multi-dimesional string array using xmlserializer DanielGifford@gmail.com Microsoft Dot NET Compact Framework 1 28th Jan 2008 10:17 PM
Redimming an array dynamically assigned from range (how to redim first dimension of a 2-D array? /or/ reverse the original array order) Keith R Microsoft Excel Programming 3 13th Nov 2007 04:08 PM
about inheritance and array Tony Johansson Microsoft C# .NET 4 20th Nov 2005 05:25 PM
XmlSerializer with array of classes =?Utf-8?B?emF0b3Blaw==?= Microsoft Dot NET 3 13th Sep 2005 12:51 PM
Inheritance and Array's Derek Microsoft Dot NET 6 15th Jan 2004 12:25 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 04:41 PM.