zoukankan      html  css  js  c++  java
  • C#如何把XSD中HexBinary类型序列化uint类型

    xml schema中有hexBinary类型, 我们在实现C#的Serialization时,一般默认把hexBinary映射为byte[],但是有些情况我们需要把 hexBinary映射为uint、int等等这样的类型。 这样我们就需要包装下, 如下:

    xml schema中定义ID节点, 类型为hexBinary。我们通过中间byte[] IDBinary转为uint ID, 实际使用中直接使用ID即可。


                   <xs:element name="ID">
                        <xs:simpleType>
                             <xs:restriction base="xs:hexBinary">
                                  <xs:length value="4"/>
                             </xs:restriction>
                        </xs:simpleType>
                   </xs:element>

            [XmlIgnore()]
            public uint ID
            {
                get;
                set;
            }

            [XmlElement("ID", DataType = "hexBinary")]
            public byte[] IDBinary
            {
                get
                {
                    return BitConverter.GetBytes(ID).Reverse().ToArray();
                }
                set
                {
                    ID = BitConverter.ToUInt32(value.Reverse().ToArray(), 0);
                }
            }
  • 相关阅读:
    转载 | float 清除浮动的7种方法
    转载 | CSS图片下面产生间隙的 6种解决方案
    (转载)内联元素设置宽高问题
    HTML/CSS:display:flex 布局教程
    HTML/CSS:block,inline和inline-block概念和区别
    上传文件
    分页查询 模糊查询 合体查询
    repeater的command用法
    窗体内的控制 跨窗体控制
    webform 跨窗体传值
  • 原文地址:https://www.cnblogs.com/muzizongheng/p/3169810.html
Copyright © 2011-2022 走看看