HighTechTalks DotNet Forums  

Xml serializer and nullable types

Dotnet Framework microsoft.public.dotnet.framework


Discuss Xml serializer and nullable types in the Dotnet Framework forum.



Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old   
Per Millard
 
Posts: n/a

Default Xml serializer and nullable types - 06-21-2006 , 10:26 AM







Using nullable types with the XmlSerializer doesn't seem to work properly when
deserialing an object containing a propertynameSpecified for the nullable
type.
The propertynameSpecified flag simply doesn't get set by the deserializer if
the nullable type property contains a value. Can anybody explain this ?
The following example demonstrates the problem

XmlSerializer xs = new XmlSerializer(typeof(valueclass));
MemoryStream ms = new MemoryStream();
valueclass c = new valueclass();
c.NullableValue = 10;
c.NullableValueSpecified = true;
xs.Serialize(ms, c);
ms.Position = 0;
c = (valueclass)xs.Deserialize(ms);
//c.NullableValueSpecified should equal true but equals false
MessageBox.Show(c.NullableValue.ToString()+"
"+c.NullableValueSpecified.ToString());

public class valueclass
{
public int? NullableValue;
[System.Xml.Serialization.XmlIgnore()]
public bool NullableValueSpecified;
}

regards

Per Millard
Systems architect


Reply With Quote
Reply




Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.