有类如下    public class OperationType
    {
        private int operationTypeId;
        private string operationTypeName;        public int OperationTypeId
        {
            get { return operationTypeId; }
            set { operationTypeId = value; }
        }        public string OperationTypeName
        {
            get { return operationTypeName; }
            set { operationTypeName= value; }
        }
    }序列化后如下  <OperationType>
    <OperationTypeId>111</OperationTypeId>
    <OperationTypeName>xxx</OperationTypeName>
  </OperationType>想要这样的  <OperationType OperationTypeId = 111>
    <OperationTypeName>xxx</OperationTypeName>
  </OperationType>有办法么?

解决方案 »

  1.   

    想要直接用XmlSerialize你想要的效果很难,基本上需要你自己写XML了。
      

  2.   

    我用的就是XmlSerialize
    我感觉是不是可以在这里加点东西实现呢?        [?加点什么??]
            public int OperationTypeId
            {
                get { return operationTypeId; }
                set { operationTypeId = value; }
            }         
      

  3.   

    [this.Attributes]
            public int OperationTypeId
            {
                get { return operationTypeId; }
                set { operationTypeId = value; }
            }
    :-)
      

  4.   

    可能是:
    [Serializable]
     public class OperationType
        {
            private int operationTypeId;
            private string operationTypeName;
            
            [XmlAttribute]
            public int OperationTypeId
            {
                get { return operationTypeId; }
                set { operationTypeId = value; }
            }        public string OperationTypeName
            {
                get { return operationTypeName; }
                set { operationTypeName= value; }
            }
        }
    即加上[XmlAttribute]即可。XmlAttribute  成员作为XML特性被序列化
    XMLElement    字段或特性作为Xml元素被序列化