将xml字符串反序列化为uint属性
是否可以使用将xml字符串反序列化为uint属性,xml,parsing,serialization,hex,uint,Xml,Parsing,Serialization,Hex,Uint,是否可以使用MyValueIs0x0001反序列化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).
MyValue
Is0x0001
反序列化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(); }
}
}
比如说:
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;
}
}
我可以避免使用额外属性的唯一方法是实现接口并实现您自己的序列化/反序列化操作。这个问题的大多数答案似乎与我的一致: