Skip to content

Instantly share code, notes, and snippets.

@lruckman
Created January 6, 2017 17:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save lruckman/5831eadf25417171241e1cc0efcece2e to your computer and use it in GitHub Desktop.
Save lruckman/5831eadf25417171241e1cc0efcece2e to your computer and use it in GitHub Desktop.
Serialization issue when property is set to null
namespace ConsoleApplication1
{
class Program
{
public class Foo
{
public string MyStr { get; set; }
}
static void Main(string[] args)
{
var serializer = new ExtendedXmlSerializer();
Console.WriteLine("Missing MyStr node in XML:");
Console.WriteLine(serializer.Serialize(new Foo { MyStr = null }));
Console.WriteLine("----");
Console.WriteLine("Constains MyStr node in XML");
Console.WriteLine(serializer.Serialize(new Foo { MyStr = "" }));
Console.ReadLine();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment