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

XmlSerializer - public readonly properties not in XML

Hi, I know the MSDN documents etc specify that readonly properties of
an object is not included in the XML that is generated - but any idea
why?

This put some rather severe limitations on how you must implement the
classes you wish to serialize with, and make the tool inpractical -
Most of the cases you will have readonly properties on a class...

Any easy work around?

IXmlSerializable?
XPath Querying Over Objects with ObjectXPathNavigator?
Nov 12 '05 #1
3 5029
Straatvark wrote:
Hi, I know the MSDN documents etc specify that readonly properties of
an object is not included in the XML that is generated - but any idea
why?


And how do you think they are gonna be set when constructing object
during deserialization?

--
Oleg Tkachenko [XML MVP]
http://blog.tkachenko.com
Nov 12 '05 #2
My easy workaround for this is to use a no-op setter.
Eg,

public class BA {
public ReportGroup[] ReportGroup;
public string ID;

private string m_Internal;

public string ReadOnlyProp {
set {}
get {return m_Internal;}
}
}
This will serialize the readonly property correctly.
However on de-serialization, the property will not be set, because the
setter does nothing.

Be aware that serialization, then de-serialization, of this type of object
will lose data.
-Dino

"Oleg Tkachenko [MVP]" <oleg@NO!SPAM!PLEASEtkachenko.com> wrote in message
news:e5**************@TK2MSFTNGP09.phx.gbl...
Straatvark wrote:
Hi, I know the MSDN documents etc specify that readonly properties of
an object is not included in the XML that is generated - but any idea
why?


And how do you think they are gonna be set when constructing object
during deserialization?

--
Oleg Tkachenko [XML MVP]
http://blog.tkachenko.com

Nov 12 '05 #3
Why do you assume that an object will always be deserialized within a .NET
environment? We have several objects that we send to our customers using a
web service that we never EVER deserialize ourselves and yet we can't use
the .NET default serialization because our read-only properties are not
serialized.

Is there some way to override the built-in behavior and tell .NET to
serialize read-only properties (because we understand that we can't
deserialize the object but we don't want to anyway so don't care)?

Phil.
"Oleg Tkachenko [MVP]" <oleg@NO!SPAM!PLEASEtkachenko.com> wrote in message
news:e5**************@TK2MSFTNGP09.phx.gbl...
Straatvark wrote:
Hi, I know the MSDN documents etc specify that readonly properties of
an object is not included in the XML that is generated - but any idea
why?


And how do you think they are gonna be set when constructing object
during deserialization?

--
Oleg Tkachenko [XML MVP]
http://blog.tkachenko.com

Nov 12 '05 #4

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

Similar topics

8
by: Harris Boyce | last post by:
Hello, I'm trying to use the FOR XML EXPLICIT clause with SQL Server to deserialize data from my database into a strongly-typed collection object that I will use throughout my application. I...
3
by: Anthony Bouch | last post by:
Hi I've been reading using the XmlSerializer with custom collections. I've discovered that when serializing a custom collection (a class that implements ICollection, IList etc.) the...
0
by: keith bannister via .NET 247 | last post by:
(Type your message here) -------------------------------- From: keith bannister Hi, I'm new to .net (as of last week) but here goes. I want to serialize/deserialize a file the conforms...
5
by: Keith Bannister | last post by:
I'm new to .net so here goes. I'm tying to deserialize a class that is associated with an XML schema. I created the C# class with xsd.exe as below: xsd.exe /c /n:somenamespace...
4
by: Steve Long | last post by:
Hello, I hope this is the right group to post this to. I'm trying to serialize a class I've written and I'd like to be able to serialze to both binary and xml formats. Binary serialization is...
8
by: cd~ | last post by:
I can provide a test app, the news server won't allow me to post the files because they are too large (93KB and 1.2KB) I downloaded the ESRI ArcXml schema and generated the classes from the...
1
by: Yewen Tang | last post by:
I have a schema file datamodel.xsd, element "properties" is declared as a type of "baseProperty". The schema file also defines "derivedProperty" is a derived type of "baseProperty". <?xml...
6
by: Beorne | last post by:
I have to use XmlSerializer to serialize a class and I've found big problems serializing properties and indexers. I assumed that if you serialize a class with public properties (or an indexers)...
2
by: Beorne | last post by:
I'm serializing a big class using XmlSerializer (I need xml serialization cause compact framework). I've learn that all my fields must be public. Ok. Now it is completly useless to serialize my...
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

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.