473,320 Members | 1,900 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.

don't serialize boolean property if false?

I've got a boolean class property that is almost always false.
How can I specify that a class property should not be included in the
xml serializer output if it is false?
I'm using [XmlAttribute]. [XmlIgnore] will never print it if it is true
either.
Nov 12 '05 #1
3 6137
Doug Holton wrote:
I've got a boolean class property that is almost always false.
How can I specify that a class property should not be included in the
xml serializer output if it is false?
I'm using [XmlAttribute]. [XmlIgnore] will never print it if it is true
either.


I found it:
[System.ComponentModel.DefaultValue(false)]
Nov 12 '05 #2
You already found one solution:

Another one would be to add another property to control the
serialization of your property:

public class MyClass
{
[XmlIgnore]
public bool MyPropSpecified;

public bool MyProp;
}

The XmlSerializer will look for the fields/properties with have the same
name stem as others and end in "Specified" to decide whether or not to
add the element.

HTH,
Christoph Schittko
MVP XML
http://weblogs.asp.net/cschittko
-----Original Message-----
From: Doug Holton [mailto:in****@spam.here]
Posted At: Friday, December 10, 2004 4:09 PM
Posted To: microsoft.public.dotnet.xml
Conversation: don't serialize boolean property if false?
Subject: Re: don't serialize boolean property if false?

Doug Holton wrote:
I've got a boolean class property that is almost always false.
How can I specify that a class property should not be included in the xml serializer output if it is false?
I'm using [XmlAttribute]. [XmlIgnore] will never print it if it is true either.


I found it:
[System.ComponentModel.DefaultValue(false)]


Nov 12 '05 #3
Jay
Is there a way to get this kind of information when you're doing the
inverse (de-serializing). For example, how can you tell in MyClass
object you just deserialized whether the MyProp element was defined as
false in the XML, or if it wasn't in the XML, and the default value
just happens to be false?
Thanks.

Nov 12 '05 #4

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

Similar topics

15
by: F. Da Costa | last post by:
Hi all, Following two sniperts of code I'm using and getting very interesting results from. ..html <tr id="1" class="segment" open="false"> This is the segment under 'investigation' ..js
1
by: Rita | last post by:
I can deserialize my Xml that contains 0/1 to bool, but when I again serialize it, value is true/false. Is there some way to force boolean value to be serialized as 0 and 1, not true or false?...
10
by: Dan | last post by:
All I Am Attempting To Serialize An Object To An XML File. Here Is The Code For That public string SaveNewSurvey( MutualSurveyObject mso_TempObject, int i_JobID ) { string s_RootFileName;...
1
by: Bill L | last post by:
Hi guys, Because of restarting application after new DLLs installed into \Bin folder , we move the session to StateServer, everything'a alright except when I try to write any simple hash table...
0
by: John Manion via .NET 247 | last post by:
Long Post, thanks for your patience... I have and XML file that looks something like this: <?xml version="1.0" encoding="utf-8" ?> <Settings> <Location> <X>30</X> <Y>40</Y> </Location>...
0
by: Marc Robitaille | last post by:
Hello everyone, I have a control which inherits from another control. I added a contextual menu to the new control. To this new control, I added a Boolean property. This property enables me to...
10
by: Henri | last post by:
In java for instance there's a way to use booleans as objects and not as value types. I would like to do the same in VB.NET so that I can check if the boolean has been explicitely defined (is not...
1
by: js | last post by:
Does anybody knows how to solve the problem? I added attribute to the following classes in Microsoft.Practices.EnterpriseLibrary.Data namespace, but I still get the error. Thanks. ...
3
by: =?Utf-8?B?UGhpbCBKb2huc29u?= | last post by:
Hi, I am using dotnet remoting with a binarry formatter. I have a property that returns a memorystream that has had a file loaded into it. When I try to access this property though I get an...
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
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
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...
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...
1
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...
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...

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.