I need to deserialize a raw xml to a particular object. However I am having issues when it comes to boolean and enum types, as case sensitivity is intact.
public MyObjectTypeDeserializeMethod(string rawXML)
{
DataContractSerializer serializer = new DataContractSerializer(typeof(MyObjectType));
MyObjectType tempMyObject = null;
try
{
// Use Memory Stream
using (MemoryStream memoryStream = new MemoryStream())
{
// Use Stream Writer
using (StreamWriter streamWriter = new StreamWriter(memoryStream))
{
// Write and Flush
streamWriter.Write(rawXML);
streamWriter.Flush();
// Read
memoryStream.Position = 0;
tempMyObject = (MyObjectType)serializer.ReadObject(memoryStream);
}
}
}
catch (Exception e)
{
throw e;
}
return tempMyObject;
}
public class MyObjectType
{
public bool boolValue {get; set;}
public MyEnumType enumValue {get; set;}
}
If the raw XML contains
<boolValue>true</boolValue>
it works fine. However it throws an exception whenever the value is different to the the previous, such as
<boolValue>True</boolValue>
No comments:
Post a Comment