473,385 Members | 1,356 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,385 software developers and data experts.

XmlSerializer: Inheritance and Read-Only Properties

All,

Please maximize for easier viewing. Assume I have a class structure as
follows:

[Serializable]
public class Foo
{
private string _hello = "Hello";

public string Hello
{
get
{
return _hello;
}
}
}

public class Bar : Foo
{
private Foo _fooBar = new Foo();
private string _message = "This is a test";

public Foo FooBar
{
get
{
return _fooBar;
}
}

public string Message
{
get
{
return _message;
}
set
{
_message = value;
}
}
}

When serializing an instance of Bar using the XmlSerializer, I only see the
property named "Message" in my resulting XML string. How can I tell the
XmlSerializer to include all of Bar including read-only properties and all
of Foo (it's base class) in the resulting XML?

Kindest Regards,
Michael


Jan 20 '06 #1
1 1269
Please disregard as it seems I'll need to implement the IXmlSerializable
interface. If anyone has other options then please let me know.

- m

"Michael Primeaux" <mj********@nospam.msn.com> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
All,

Please maximize for easier viewing. Assume I have a class structure as
follows:

[Serializable]
public class Foo
{
private string _hello = "Hello";

public string Hello
{
get
{
return _hello;
}
}
}

public class Bar : Foo
{
private Foo _fooBar = new Foo();
private string _message = "This is a test";

public Foo FooBar
{
get
{
return _fooBar;
}
}

public string Message
{
get
{
return _message;
}
set
{
_message = value;
}
}
}

When serializing an instance of Bar using the XmlSerializer, I only see
the property named "Message" in my resulting XML string. How can I tell
the XmlSerializer to include all of Bar including read-only properties and
all of Foo (it's base class) in the resulting XML?

Kindest Regards,
Michael

Jan 21 '06 #2

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

Similar topics

3
by: Integer Software | last post by:
Hi. I have a really simple set of classes that writes 2 pathnames to a xml file. I can write the default ok. Then if I change 1 pathname to a shorter one, then rewrite the xml file, the remains...
1
by: Bluetears76 | last post by:
Hi I have a hirachy of classes which are Message(base), then FileMessage and ChatMessage (extended) I want to serialize the objects and when i am deserizaling i dont know if i am getting...
11
by: Nick Flandry | last post by:
Hi all, When I run this code: XmlSerializer theXS; try { theXS = new XmlSerializer(typeof(TableInfo)); } catch( System.Exception eAll )
3
by: grs | last post by:
I am using some Microsoft examples that: 1. Serialize an object using XmlSerializer and write a file out to the harddrive. 2. Read back in the file using XmlDocument.Load and populate a string. ...
2
by: Jarda | last post by:
Hi all, i'm looking for some performance comparison some charts. I have read the xmlserializer is better, more flexible and faster (analyzing data types in constructor), but there are some...
1
by: Xing Zhou | last post by:
It seems that XmlSerializer.FromTypes() method cannot handle inner class properly .. or is there anything I did wrong? The following code will throw a reflection exception at FromTypes() method....
0
by: William Stacey [MVP] | last post by:
Had a method that got some string info from mp3 tags in N files and serializes this class and deserializes at other side. Works ok except sometimes get chars that choke the XmlSerializer. After...
4
by: Ultrakorne | last post by:
hi, i have some problems with my client talk to my server... i am using xmlserializer to serialize object and send them to the other side of the connection. I need to send / recive by both client...
1
by: kimtherkelsen | last post by:
Hi, I want to send XML data from a server to some clients over a network connection using the TCP/IP protocol. If I send the XMLs as byte arrays I need to insert header information in the data to...
2
by: =?Utf-8?B?U2hhd24=?= | last post by:
Hi; I would like to be able to use the XMLSerializer to serialize and deserialize a dictionary. is that possible? i know that you can serialize an object that implements the ICollection interface....
1
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: 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...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.