0

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(); }

    }
}
Barry Kaye
  • 7,682
  • 6
  • 42
  • 64
Odrai
  • 2,163
  • 2
  • 31
  • 62

1 Answers1

0

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;
    }
}
JLRishe
  • 99,490
  • 19
  • 131
  • 169
  • The only way I can forsee avoiding the extra property is to implement the [IXmlSerializable](http://msdn.microsoft.com/en-us/library/system.xml.serialization.ixmlserializable.aspx) interface and implement your own serialization/deserialization operations. Most of the answers to this question seem to be consistent with mine: http://stackoverflow.com/questions/3840803/how-to-output-hex-numbers-via-xml-serialization-in-c – JLRishe Jan 14 '13 at 12:13