Block, Jeffrey A. [mailto:[EMAIL PROTECTED]] wrote:

> No, the only one that I can think of is XmlRoot that names
> the root element of the Xml serialization process, if this
> doesn't exist, it is the name of the class by default.  The
> newly discovered attributes need to be applied to the class
> that actually uses the ArrayList descendent class, not the
> class itself.

If all abstract items in the array are to be serialized using the same
element name, then you only need to specify that single
XmlArrayItemAttribute on the property with no type... like so:

<codeSnippet language="C#">
[XmlArray("myItems")]
[XmlArrayItem("item")]
public ArrayList Items
{
        ...
}
</codeSnippet>

In this scenario all objects in the ArrayList will be serialized as "<item>"
elements and their specific types will supply child-elements and xml
attributes via the type's own xml serialization attributes. In order for
this to work though, you must construct an instance of the serializer with
all the known types stored in the array property at that given point in time
using the XmlSerializer::ctor(Type, Type[]) overload.

However, If you want items of a specific type to be serialized with a
different element name (other than "<item>") you either need to supply them
statically as additional XmlArrayItemAttributes at compile time or configure
the serializer with an XmlAttributeOverrides instance at runtime.

In either case, the serializer must know all types it will be dealing with
at construction time either explicitly through one of the overloaded
constructors or implicitly via the serialization attributes applied to the
root type and all types that can be chased down the graph from there.

HTH,
Drew

You can read messages from the DOTNET archive, unsubscribe from DOTNET, or
subscribe to other DevelopMentor lists at http://discuss.develop.com.

Reply via email to