Problem with serialization of polymorphic array

M

Michal Piatkowski

I have a problem with serialization of a polymorphic
array.
It has attributes defined XmlArray and XmlArrayItem for
XML serialization. The attribute specifies Type1 but as my
array is polymorphic I really want to have more than one
type inside of it. So I have objects of Type2, Type3, etc.
which inherit from Type1. They are in my array.
To be able to serialize the array, I would need to supply
all the types (Type2, Type3, etc...)
as XmlType attributes of my array during design time.
Otherwise I get Serializer exception. However, I load my
types dynamicly at runtime and I don't know what exact
types in my array will appear so I am not able to specify
them as attributes. As far as I know it is not
possible to change the value of an attribute at runtime.

What should I do to be able to serialize an array with
objects of types that are not known at design time ?
Can I modify value of an attribute or I should do
something else ?

Thanks

Michal Piatkowski
 
P

Peter Koen

[email protected]:

What should I do to be able to serialize an array with
objects of types that are not known at design time ?
Can I modify value of an attribute or I should do
something else ?

Thanks

Michal Piatkowski

you could Iterate over the array and call GetType() for each item. Store
these types into an array and then use Reflection to extend the
CustomAttributes of that array with your new types before Serializing it.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top