Serializing a derived class

T

Tina

Is there any attribute I can use to serialize the class 'Data' below
such that I get:

<Data>
<MyOwnBaseClass>
<A>some_values</A>
</MyOwnBaseClass>
</Data>

from the serializable class defined below?

public class Data
{
[XmlArrayItem(Type = typeof(DerviedClass))]
public MyOwnBaseClass[] Base;
}

public class MyOwnBaseClass
{
}

public class DerviedClass : MyOwnBaseClass
{
public string A;
}

I don't want to show the DerviedClass name as a tag, but if I serialize
the class I will get:

<Data>
<MyOwnBaseClass>
<DerviedClass>
<A>some_values</A>
</DerivedClass>
</MyOwnBaseClass>
</Data>

instead of what I actually want shown above.
 
T

Tina

I am using XMLSerialization. Note that I used [XMLArrayItem] as an
attribute to one of my members.
Tina,

You should use XMLSerialization instead of Serialization.

http://support.microsoft.com/kb/314150/EN-US/

Cor

Tina said:
Is there any attribute I can use to serialize the class 'Data' below
such that I get:

<Data>
<MyOwnBaseClass>
<A>some_values</A>
</MyOwnBaseClass>
</Data>

from the serializable class defined below?

public class Data
{
[XmlArrayItem(Type = typeof(DerviedClass))]
public MyOwnBaseClass[] Base;
}

public class MyOwnBaseClass
{
}

public class DerviedClass : MyOwnBaseClass
{
public string A;
}

I don't want to show the DerviedClass name as a tag, but if I serialize
the class I will get:

<Data>
<MyOwnBaseClass>
<DerviedClass>
<A>some_values</A>
</DerivedClass>
</MyOwnBaseClass>
</Data>

instead of what I actually want shown above.
 

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