473,320 Members | 2,083 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Serializing a derived class

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.

Sep 6 '06 #1
2 1960
Tina,

You should use XMLSerialization instead of Serialization.

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

Cor

"Tina" <ms******@gmail.comschreef in bericht
news:11*********************@p79g2000cwp.googlegro ups.com...
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.

Sep 6 '06 #2
I am using XMLSerialization. Note that I used [XMLArrayItem] as an
attribute to one of my members.

Cor Ligthert [MVP] wrote:
Tina,

You should use XMLSerialization instead of Serialization.

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

Cor

"Tina" <ms******@gmail.comschreef in bericht
news:11*********************@p79g2000cwp.googlegro ups.com...
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.
Sep 6 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: big A | last post by:
I am receiving an error stating that File or Assembly name <filname.dll>, or one of its dependencies, was not found In one assembly I have three abstract classes In another I have three...
2
by: Aleksei Guzev | last post by:
Imagine one writing a class library CL1 for data storage. He defines classes ‘DataItem’ and ‘DataRecord’ so that the latter contains a collection of the former. And he derives class ‘IntItem’ from...
0
by: Ante Smolcic | last post by:
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...
1
by: Aidan Glendye | last post by:
Hi, I am trying to store various objects within session. Due to the site being hosted in a web farm we are going to have to use either State Server or SQL Server to persist the data in...
0
by: Redowl | last post by:
Apologies if this has been covered in an early question, but I am having difficulty serializing a derived class. The base class has a property which is marked as MustOverride, but when I serialize...
1
by: Peter Nofelt | last post by:
Hey All, I am having issue with serializing a class and its base class using ..net 2.0. I am using IXmlSerializable I've provided code displaying my at the bottom of this post. Thanks ahead...
0
by: Craig Buchanan | last post by:
i am trying to build an application that uses plugins to extend the business functionality of an application. i've decided to use inheritance of abstract classes as the mechanism to do this. ...
2
by: she_prog | last post by:
I have a class derived from UserControl. I need to serialize an object of this class, but only some properties of it, as not all properties are serializable (some of the properties coming from...
12
by: Cagdas Ozgenc | last post by:
Greetings, When directly serializing C++ structures to a file with the standard library functions giving the address of the data and length of structure using the sizeof operator, do I risk...
0
by: Shaul | last post by:
Hi, My goal is to serialize a collection of type IList<AbstractClass> which contains derived objects instances. My domain object model is a bit complex so I've created a demmi one: public...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.