I think I'm missing something in my C# Serialization understanding.
I am serializing a C# class to XML to transfer across a web service. For simplicity's sake, I have a class with only three properties:
public partial class MyInfo : SerializableObject
{
private string ssnField;
private string suffixField;
private integer suffixIDField;
public MyInfo()
{
this.ssnField = string.Empty;
this.suffixField = string.Empty;
this.suffixIDField = 0;
}
public string SSN
{
get { return this.ssnField; }
set { this.ssnField = value; }
}
public string Suffix
{
get { return this.suffixField; }
set { this.suffixField = value; }
}
public integer SuffixID
{
get { return this.suffixIDField; }
set { this.suffixIDField = value; }
}
}
And here's the gist of the serializer:
using (XmlTextWriter xmlTextWriter = new XmlTextWriter(memoryStream, Encoding.UTF8) { Formatting = Formatting.Indented })
{
xmlSerializer.Serialize(xmlTextWriter, this);
memoryStream = (MemoryStream)xmlTextWriter.BaseStream;
xmlText = new UTF8Encoding().GetString(memoryStream.ToArray());
memoryStream.Dispose();
}
And here's my output: Neither SSN or Suffix get set beyond the string.empty call. SSN shows up in the XML, Suffix does not. Anyone know why?
<SSN />
<SuffixID>0</SuffixID>
I'd prefer to not pass empty fields (like Suffix) but I'd settle to know why one appears, and one does not.
Thanks much.