【问题标题】:Deserialize xml string to uint property将 xml 字符串反序列化为 uint 属性
【发布时间】:2013-01-14 10:33:24
【问题描述】:

是否可以使用 MyValue0x0001 反序列化 XML 文件并将其反序列化为 uint 属性?实现这一点的最佳方法是什么?

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

    }
}

【问题讨论】:

    标签: xml parsing serialization hex uint


    【解决方案1】:

    怎么样:

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

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-05-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-10-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多