serializing iderived classes in arrays

From: Ante Smolcic (spam_at_supersmola.net)
Date: 01/27/05


Date: Thu, 27 Jan 2005 13:40:52 +0100


Hi all,

I have an ArrayList that contains items of type A. I declared the
XmlArrayItem atribute for that type.

Now I have an derived type B (from A) also contained in the ArrayList
but I get an error when serializing.

Can this be made without redeclaring the ArrayList special attributes?
The problem is that the class B is in different namespace!

public class Container
{
  [XmlArray, XmlArrayItem(typeof(A))]
  public ArrayList Items = new ArrayList();
}

public class A
{
  public string Name = "A object";
  public A()
  {
  }
}

--- (different namespace!) -----
public class B : A
{
  public B()
  {
    Name = "B object";
  }
}

I think I could use XmlAttributeOverrides but this way I'll have to
change the serializing code every time I derive a new class from A. :(

-- 
That's me favorite shirt. That's me only shirt!