How to deserialize null array to null in c#?
Posted
by Aen Sidhe
on Stack Overflow
See other posts from Stack Overflow
or by Aen Sidhe
Published on 2010-03-30T09:56:27Z
Indexed on
2010/03/30
10:13 UTC
Read the original article
Hit count: 363
Here is my class:
public class Command
{
[XmlArray(IsNullable = true)]
public List<Parameter> To { get; set; }
}
When I serialize an object of this class:
var s = new XmlSerializer(typeof(Command));
s.Serialize(Console.Out, new Command());
it prints as expected (xml header and default MS namespaces are omitted):
<Command><To xsi:nil="true" /></Command>
When I took this xml and tried to deserialize it I got stucked, because it always print "Not null":
var t = s.Deserialize(...);
if (t.To == null)
Console.WriteLine("Null");
else
Console.WriteLine("Not null");
How to force deserializer to make my list null, if it is null in xml?
© Stack Overflow or respective owner