473,386 Members | 1,721 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: how to not serialize properties?

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 get/set properties, but I
haven't found an anttribute like
[NonSerialized]
working foer properties.
Any help?

Mar 1 '07 #1
2 10111
"Beorne" <ma*******@gmail.comwrote in message
news:11**********************@m58g2000cwm.googlegr oups.com...
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 get/set properties, but I
haven't found an anttribute like
[NonSerialized]
working foer properties.

Why do you think all your fields must be public? When I serialize objects
to XML using he XmlSerializer, my fields are private and the serializer
works off of the public properties. The help documentation from MSDN
confirms this is the correct behavior - "The Serialize method converts the
public fields and read/write properties of an object into XML".

So leave your fields private, and have them accessible through public
properties, noting that the get and set must both be public.

That being said, if you want the XmlSerializer to not serialize a property
or field, add an XmlIgnoreAttribute to it.
--
Tom Porterfield

Mar 1 '07 #2
The attribute is [XmlIgnore] - however I agree with the other
respondant; working with public fields is an ugly way to go...

Marc

Mar 1 '07 #3

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

Similar topics

2
by: | last post by:
Hey, I have made a method that would take any object o and an array of extraTypes to construct a XmlSerializer object then call .Serialize(stream, object)... When I have this called within...
3
by: Peter Cresswell | last post by:
Hello everyone, I would like to serialize an object to XML. Currently my code will serialize all of the public properties that are value types, but not my public properties that have get...
0
by: Ashish | last post by:
Iam trying to create a xml file by serializing a custom business object. Iam using a xmltextwriter, but the problem there are invalid characters at the end of the generated file anyone knows a...
1
by: ocampoj | last post by:
I am having a problem serializing an object. I have a very simple class. public class Phone : SwcDomainObject { private string areaCode; private string prefix; private string suffix;...
1
by: qrli | last post by:
public class ToBeSerialized { // This field is alway ignored by XmlSerializer public Color color; } How can I make that field serialized correctly? thx in advance!
2
by: Jinsong Liu | last post by:
I have following 3 classes public class MyMainClass { MyCollection<MyObject> m_oMyObjectCollection = null; private string m_sID = string.Empty; public MyCollection<MyObject> Collection {
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)...
1
by: =?Utf-8?B?Q2hyaXN0aWFu?= | last post by:
hello everyone, I'm using the XmlSerializer to generate Xml-Files of my classes. I do have some float's and double's that also should get serialized. At the moment, XmlSerializer generates...
2
by: =?Utf-8?B?TW91dGhPZk1hZG5lc3M=?= | last post by:
How can I add an MD5 hash to XMLSerializer.Serialize without corrupting the content of the file; then how to read it back to verify is correct? I'd like to code up something (see below) that...
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:
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...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.