restsharp/RestSharp — pull request #169 by PaulCampbell (2011-10-17 20:01:33+00:00)
Title: XML Deserialization of nullable types with attributes

Hi there,

When trying to deserialize a nullable type, if the element has any attributes, the value is set to "", which is problematic.

here's a test:

[Fact]
public void Can_Deserialize_Empty_Elements_With_Attributes_to_Nullable_Values()
{
var doc = CreateXmlWithAttributesAndNullValues();

var xml = new XmlDeserializer();
var output = xml.Deserialize(new RestResponse { Content = doc });

Assert.Null(output.Id);
Assert.Null(output.StartDate);
Assert.Null(output.UniqueId);
}

private static string CreateXmlWithAttributesAndNullValuesAndPopulatedValues()
{
var doc = new XDocument();
var root = new XElement("NullableValues");

var idElement = new XElement("Id", null);
idElement.SetAttributeValue("SomeAttribute", "SomeAttribute_Value");
root.Add(idElement,
new XElement("StartDate", null),
new XElement("UniqueId", new Guid(GuidString))
);

doc.Add(root);

return doc.ToString();
}
I have attached a pull request, with a further test and a fix.

Please give me a shout if you would like me to change anything, or if there's any problem

Thanks guys!