Deserialize xml string to uint property

只愿长相守 提交于 2019-12-13 06:31:47

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!