将xml字符串反序列化为uint属性

将xml字符串反序列化为uint属性

本文介绍了将xml字符串反序列化为uint属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以使用 MyValue 0x0001 反序列化XML文件并将其反序列化为uint属性?

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

    }
}


推荐答案

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

这篇关于将xml字符串反序列化为uint属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-29 18:02