I have a boolean property that I want to serialize to disk using XmlSerializer.
I noticed that if the property includes the attribute "DefaultValue(t rue)"
or "DefaultValue(f alse)" that the property will not serialilze to an XML
file. If the attribute is removed the serialization occurs just fine.
Is there a way around this bug? This behavior seems to work with any type
of property.
--
-----------
Thanks,
Steve 4 5357
Do you have a code sample here? I am pretty sure that I have used
[XmlAttribute, DefaultValue(fa lse)] (to abbreviate the xml fragment)
and AFAIK it worked just fine. The only related thing I am aware of is
a known bug in WSE3 relating to [XmlAttribute] on byte[] properties.
Also - is this using XmlSerializer directly, or is it during usage in a
web-service? If the latter, then you should also clarify the specifics:
vanilla SOAP? WSE? (and if WSE, which version)
Marc
Futher to my previous answer, what do you mean "will not serialize"?
As, no, by definition if you have DefaultValue(fa lse), and the value
*is* false, then it *won't* go into the file. This is the expected
behaviour, and is similar to the way the forms designer doesn't write
code for properties you haven't changed.
If you don't want this behaviour, then either don't specify a
DefaultValue, else perform the serialization manually using
IXmlSerializabl e (IIRC; don't have VS to hand).
Marc
Thank you. I didn't realize that if the "default value assigned in the init"
and the "DefaultValue(. ..)" - if the same - would not write the value out. I
just verified in my sample code and your statements are correct. Thank you.
Where did you learn that the behavior (when they are the same) is NOT to
write out the value?
--
-----------
Thanks,
Steve
"Marc Gravell" wrote:
Futher to my previous answer, what do you mean "will not serialize"?
As, no, by definition if you have DefaultValue(fa lse), and the value
*is* false, then it *won't* go into the file. This is the expected
behaviour, and is similar to the way the forms designer doesn't write
code for properties you haven't changed.
If you don't want this behaviour, then either don't specify a
DefaultValue, else perform the serialization manually using
IXmlSerializabl e (IIRC; don't have VS to hand).
Marc
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Craig Schneider |
last post by:
// Is there any way to override the XML Serialization of the following
SimpleClass
// to turn off the DefaultValue of a boolean? Sure, I can override
the DefaultValue from
// true to false, but that is not what I want/need. I really need to
just override the fact
// that the developer ever supplied a DefaultValue. Setting an
override DefaultValue of null
// or "new object()" errors. Any help would be appreciated.
|
by: Justine |
last post by:
Hi All,
I would like to know where & when exactly we would have a
need for attributes. A realistic example.
Thanz in Advance,
Justine
|
by: schneider |
last post by:
Hello,
Have an issue with a property using the DefaultValue(True) attribute.
Imports System.ComponentModel
Public Class Class1
Private m_testValue As Boolean
|
by: tinyabs |
last post by:
Hi,
How do it set the default value of PopupSize?
public Size PopupSize
{
|
by: Rasmus Kromann-Larsen |
last post by:
Hello,
I'm currently playing around with the XmlSerializer to replace my old
handmade Xml parsing code, but am having a few small issues with
default values and derived classes.
Say we have classes A, B and C:
abstract class A
{
| |
by: Peter Hartlén |
last post by:
Hi!
What's the correct syntax for the default value design time attribute, using
classdiagram view and Custom Attributes dialog.
For a boolean:
DefaultValue(true)
DefaultValue("true")
DefaultValue("bool","true")
|
by: Henrik Dahl |
last post by:
Hello!
I have an xml schema which has a date typed attribute. I have used xsd.exe
to create a class library for XmlSerializer. The result of
XmlSerializer.Serialize(...) should be passed as the value for the parameter
of an SqlCommand for inserting the xml document in a column of a table where
the column is typed to be of the same xml schema.
This all sounds simple, but SQL Server REQUIRES the timezone to be specified
for date values....
|
by: Johnny Jörgensen |
last post by:
Does anybody know how to correctly specify the defaultvalue attribute for a
property whose type is an enum.
Example:
Public Enum TestValues
Value1=1
Value2=2
End Enum
|
by: =?Utf-8?B?bWljaGFlbCBzb3JlbnM=?= |
last post by:
Prior to C# 3.0, I would typically define a property of a custom user control
with pattern A:
=== PATTERN A ==========
private bool myBool = true;
public bool MyBool {
get { return myBool; }
set { myBool = value; }
}
======================
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |