问题
Is it possible to deserialize a XML file with MyValue
is 0x0001
and deserialize it to an uint property? What's the best way to implement this?
public class MyClass
{
private string myValue;
public uint MyValue
{
//checkValue method checks if myValue is a decimal or hex and number (returns an uint value).
get { return checkValue(myValue); }
set { myValue = value.ToString(); }
}
}
回答1:
How about something like:
public class MyClass
{
private uint? _myValue;
[XmlIgnore]
public uint MyValue
{
get{ return _myValue ?? checkValue(MyValueString); }
set{ _myValue = value; }
}
[XmlElement("MyValue")]
public string MyValueString
{
//checkValue method checks if myValue is a decimal or hex and number (returns an uint value).
get; set;
}
}
来源:https://stackoverflow.com/questions/14316771/deserialize-xml-string-to-uint-property