重写xml特性。

private readonly static List<XmlSerializerModel> propertylist = new List<XmlSerializerModel>() {
                #region FlightProductGroupList
                new XmlSerializerModel{ XmlArrayAttributeName="FlightProductGroupList",  XmlArrayAttributeType=typeof(Ctrip.AM.IPS.EntityLib.CtripSDK.SearchResultTypeDomesticIPS),
                    XmlArrayItemsName="FlightProductGroupType", XmlArrayItemType=typeof(Ctrip.AM.IPS.EntityLib.CtripSDK.FlightProductGroupType)},

new XmlSerializerModel{ XmlArrayAttributeName="FlightSegmentList", XmlArrayAttributeType=typeof(Ctrip.AM.IPS.EntityLib.CtripSDK.FlightProductGroupType),
                    XmlArrayItemsName="FlightSegmentType", XmlArrayItemType=typeof(Ctrip.AM.IPS.EntityLib.CtripSDK.FlightSegment)},

new XmlSerializerModel{ XmlArrayAttributeName="FlightProductList", XmlArrayAttributeType=typeof(Ctrip.AM.IPS.EntityLib.CtripSDK.FlightProductGroupType),
                    XmlArrayItemsName="int", XmlArrayItemType=typeof(int)},
                #endregion
                #region FlightListGroupList
                new XmlSerializerModel{ XmlArrayAttributeName="FlightListGroupList",  XmlArrayAttributeType=typeof(Ctrip.AM.IPS.EntityLib.CtripSDK.SearchResultTypeDomesticIPS),
                    XmlArrayItemsName="OrigDestFlightListGroupType", XmlArrayItemType=typeof(Ctrip.AM.IPS.EntityLib.CtripSDK.OrigDestFlightListGroupType)},

new XmlSerializerModel{ XmlArrayAttributeName="FlightList",  XmlArrayAttributeType=typeof(Ctrip.AM.IPS.EntityLib.CtripSDK.OrigDestFlightListGroupType),
                    XmlArrayItemsName="FlightEntityType", XmlArrayItemType=typeof(Ctrip.AM.IPS.EntityLib.CtripSDK.FlightEntityType)},

new XmlSerializerModel{ XmlArrayAttributeName="FlightFeeInfoList",  XmlArrayAttributeType=typeof(Ctrip.AM.IPS.EntityLib.CtripSDK.FlightEntityType),
                    XmlArrayItemsName="FlightFeeInfoTypeDomestic", XmlArrayItemType=typeof(Ctrip.AM.IPS.EntityLib.CtripSDK.FlightFeeInfoTypeDomestic)},

new XmlSerializerModel{ XmlArrayAttributeName="FeeList",  XmlArrayAttributeType=typeof(Ctrip.AM.IPS.EntityLib.CtripSDK.FlightFeeInfoTypeDomestic),
                    XmlArrayItemsName="FeeInfoType", XmlArrayItemType=typeof(Ctrip.AM.IPS.EntityLib.CtripSDK.FeeInfoType)},

new XmlSerializerModel{ XmlArrayAttributeName="SubClassList",  XmlArrayAttributeType=typeof(Ctrip.AM.IPS.EntityLib.CtripSDK.FlightEntityType),
                    XmlArrayItemsName="SubClassEntityListType", XmlArrayItemType=typeof(Ctrip.AM.IPS.EntityLib.CtripSDK.SubClassEntityListType)},

new XmlSerializerModel{ XmlArrayAttributeName="FlightStopList",  XmlArrayAttributeType=typeof(Ctrip.AM.IPS.EntityLib.CtripSDK.FlightEntityType),
                    XmlArrayItemsName="FlightStopEntityType", XmlArrayItemType=typeof(Ctrip.AM.IPS.EntityLib.CtripSDK.FlightStopEntityType)},

new XmlSerializerModel{ XmlArrayAttributeName="StandardPriceList",  XmlArrayAttributeType=typeof(Ctrip.AM.IPS.EntityLib.CtripSDK.FlightEntityType),
                    XmlArrayItemsName="StandardPriceType", XmlArrayItemType=typeof(Ctrip.AM.IPS.EntityLib.CtripSDK.StandardPriceType)},
                #endregion
                #region ProductList
                new XmlSerializerModel{ XmlArrayAttributeName="ProductList",  XmlArrayAttributeType=typeof(Ctrip.AM.IPS.EntityLib.CtripSDK.SearchResultTypeDomesticIPS),
                    XmlArrayItemsName="ProductEntityType", XmlArrayItemType=typeof(Ctrip.AM.IPS.EntityLib.CtripSDK.ProductEntityType)},

new XmlSerializerModel{ XmlArrayAttributeName="TotalPriceInfoList",  XmlArrayAttributeType=typeof(Ctrip.AM.IPS.EntityLib.CtripSDK.ProductEntityType),
                    XmlArrayItemsName="PriceInfoType", XmlArrayItemType=typeof(Ctrip.AM.IPS.EntityLib.CtripSDK.PriceInfoTypeDomestic)},

new XmlSerializerModel{ XmlArrayAttributeName="PolicyIndexList",  XmlArrayAttributeType=typeof(Ctrip.AM.IPS.EntityLib.CtripSDK.ProductEntityType),
                    XmlArrayItemsName="int", XmlArrayItemType=typeof(int)},
                #endregion
                #region PolicyRuleList
                new XmlSerializerModel{ XmlArrayAttributeName="PolicyRuleList",  XmlArrayAttributeType=typeof(Ctrip.AM.IPS.EntityLib.CtripSDK.SearchResultTypeDomesticIPS),
                    XmlArrayItemsName="PolicyRuleType", XmlArrayItemType=typeof(Ctrip.AM.IPS.EntityLib.CtripSDK.PolicyRuleType)},
                #endregion
                #region PolicyInfoList
                     new XmlSerializerModel{ XmlArrayAttributeName="PolicyInfoList",  XmlArrayAttributeType=typeof(Ctrip.AM.IPS.EntityLib.CtripSDK.SearchResultTypeDomesticIPS),
                    XmlArrayItemsName="PolicyInfoType", XmlArrayItemType=typeof(Ctrip.AM.IPS.EntityLib.CtripSDK.PolicyInfoType)},
                     
                      new XmlSerializerModel{ XmlArrayAttributeName="PostCityList",  XmlArrayAttributeType=typeof(Ctrip.AM.IPS.EntityLib.CtripSDK.DeliveryInfoType),
                    XmlArrayItemsName="string", XmlArrayItemType=typeof(string)},

new XmlSerializerModel{ XmlArrayAttributeName="DeliveryCityList",  XmlArrayAttributeType=typeof(Ctrip.AM.IPS.EntityLib.CtripSDK.DeliveryInfoType),
                    XmlArrayItemsName="string", XmlArrayItemType=typeof(string)},

new XmlSerializerModel{ XmlArrayAttributeName="ItineraryPriceInfoList",  XmlArrayAttributeType=typeof(Ctrip.AM.IPS.EntityLib.CtripSDK.PolicyInfoType),
                    XmlArrayItemsName="PriceInfoType", XmlArrayItemType=typeof(Ctrip.AM.IPS.EntityLib.CtripSDK.PriceInfoTypeDomestic)},

new XmlSerializerModel{ XmlArrayAttributeName="ApplicableTravelerCategoryList",  XmlArrayAttributeType=typeof(Ctrip.AM.IPS.EntityLib.CtripSDK.SaleControlEntityType),
                    XmlArrayItemsName="TravelerCategoryCodeType", XmlArrayItemType=typeof(Ctrip.AM.IPS.EntityLib.CtripSDK.TravelerCategoryCodeType)},

new XmlSerializerModel{ XmlArrayAttributeName="AcceptableIDCardTypeList",  XmlArrayAttributeType=typeof(Ctrip.AM.IPS.EntityLib.CtripSDK.SaleControlEntityType),
                    XmlArrayItemsName="IDCardType", XmlArrayItemType=typeof(Ctrip.AM.IPS.EntityLib.CtripSDK.IDCardType)},

new XmlSerializerModel{ XmlArrayAttributeName="AcceptablePaymentWayList",  XmlArrayAttributeType=typeof(Ctrip.AM.IPS.EntityLib.CtripSDK.SaleControlEntityType),
                    XmlArrayItemsName="PaymentWayType", XmlArrayItemType=typeof(Ctrip.AM.IPS.EntityLib.CtripSDK.PaymentWayType)},

new XmlSerializerModel{ XmlArrayAttributeName="PaymentCardTypeList",  XmlArrayAttributeType=typeof(Ctrip.AM.IPS.EntityLib.CtripSDK.PaymentWayType),
                    XmlArrayItemsName="PaymentCardTypeType", XmlArrayItemType=typeof(Ctrip.AM.IPS.EntityLib.CtripSDK.PaymentCardTypeType)},

new XmlSerializerModel{ XmlArrayAttributeName="AcceptablePaymentCardTypeList",  XmlArrayAttributeType=typeof(Ctrip.AM.IPS.EntityLib.CtripSDK.SaleControlEntityType),
                    XmlArrayItemsName="PaymentCardTypeType", XmlArrayItemType=typeof(Ctrip.AM.IPS.EntityLib.CtripSDK.PaymentCardTypeType)},

new XmlSerializerModel{ XmlArrayAttributeName="GiftInfoList",  XmlArrayAttributeType=typeof(Ctrip.AM.IPS.EntityLib.CtripSDK.MarketingStrategyEntityType),
                    XmlArrayItemsName="GiftInfoType", XmlArrayItemType=typeof(Ctrip.AM.IPS.EntityLib.CtripSDK.GiftInfoType)},

new XmlSerializerModel{ XmlArrayAttributeName="InsuranceInfoList",  XmlArrayAttributeType=typeof(Ctrip.AM.IPS.EntityLib.CtripSDK.MarketingStrategyEntityType),
                    XmlArrayItemsName="InsuranceInfoType", XmlArrayItemType=typeof(Ctrip.AM.IPS.EntityLib.CtripSDK.InsuranceInfoType)},

new XmlSerializerModel{ XmlArrayAttributeName="PolicyRuleIndexList",  XmlArrayAttributeType=typeof(Ctrip.AM.IPS.EntityLib.CtripSDK.PolicyInfoType),
                    XmlArrayItemsName="int", XmlArrayItemType=typeof(int)},
                #endregion
            };

private class XmlSerializerModel
        {
            public string XmlArrayAttributeName { get; set; }

public string XmlArrayItemsName { get; set; }

public Type XmlArrayItemType { get; set; }

public Type XmlArrayAttributeType { get; set; }

}

private class XmlSerializerSingleton
        {
            private static XmlSerializer _instance = null;
            private static object _lock = new object();
            private XmlSerializerSingleton()
            {
            }
            public static XmlSerializer GetInstance
            {
                get
                {
                    if (_instance == null)
                    {
                        lock (_lock)
                        {
                            if (_instance == null)
                            {
                                try
                                {
                                    var attrOverrides = new XmlAttributeOverrides();
                                    //遍历静态list
                                    propertylist.ForEach(item =>
                                    {
                                        var attrArray = new System.Xml.Serialization.XmlAttributes();
                                        //定义xmlarray特性
                                        attrArray.XmlArray = new System.Xml.Serialization.XmlArrayAttribute(item.XmlArrayAttributeName);
                                        //xmlarray 添加子节点特性
                                        attrArray.XmlArrayItems.Add(new System.Xml.Serialization.XmlArrayItemAttribute(item.XmlArrayItemsName, item.XmlArrayItemType));
                                        //重写xmlarray特性
                                        attrOverrides.Add(item.XmlArrayAttributeType, item.XmlArrayAttributeName, attrArray);
                                    });
                                    _instance = new XmlSerializer(typeof(SearchResultTypeDomesticIPS), attrOverrides);
                                }
                                catch (Exception)
                                {

throw;
                                }

}
                        }
                    }
                    return _instance;
                }
            }
        }
    }

时间: 2024-08-25 08:25:25

重写xml特性。的相关文章

xml特性重载

public class Group     { public string GroupName;         [XmlIgnore]         public string Comments;     } 在序列化时,其结果如下所示 <?xml version="1.0" encoding="utf-8"?> <Group xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance&

XML特性总结

语法: 1.所有 XML 元素都须有关闭标签 在XML中省略关闭标签是非法的,所有元素都必须要有关闭标签. <p>This is a paragraph</p> <p>This is another paragraph</p> 2.XML 标签对大小写敏感 XML 标签对大小写敏感.在 XML 中,标签 <Letter> 与标签 <letter> 是不同的.必须使用相同的大小写来编写打开标签和关闭标签: <Message>

[.net 面向对象程序设计进阶] (11) 序列化(Serialization)(三) 通过接口IXmlSerializable实现XML序列化及XML通用类

[.net 面向对象程序设计进阶] (11) 序列化(Serialization)(三) 通过接口IXmlSerializable实现XML序列化及XML通用类 本节导读:本节主要介绍通过序列化接口IXmlSerializable实现XML序列化和反序列化,整理了XML基础操作及序列化的通用类(包括XML及节点的基础读写操作,XML到DataSet\DataTable互转换操作,XML序列化及反序列化通用方法等). 读前必备: A.类和类的实例 [.net 面向对象编程基础]  (9) 类和类的

【转】Xml序列化

XML序列化是将对象的公共属性和字段转换为XML格式,以便存储或传输的过程.反序列化则是从XML输出中重新创建原始状态的对象.XML序列化中最主要的类是XmlSerializer类.它的最重要的方法是Serialize和Deserialize方法,它位于System.Xml.Serialization命名空间. 一.XML序列化基本要点 在本节开始之前,首先来看一个最简单的示例: namespace 学习测试 { class Program { static void Main(string[]

.net学习笔记---xml序列化

XML序列化是将对象的公共属性和字段转换为XML格式,以便存储或传输的过程.反序列化则是从XML输出中重新创建原始状态的对象.XML序列化中最主要的类是XmlSerializer类.它的最重要的方法是Serialize和Deserialize方法,它位于System.Xml.Serialization命名空间. 一.XML序列化基本要点 在本节开始之前,首先来看一个最简单的示例: namespace 学习测试 { class Program { static void Main(string[]

.net xml 增删改查基础复习及干货分享

今天做做项目时,有一个需求需要用到一些固定的文本数据,觉得将这些需要存储的信息直接写在代码里很不友好,放在数据库中存储又觉得不够方便,自然就想到了使用xml来进行操作,我平常在项目中其实用到xml的机会并不多,今天既然碰到了,就再温故知新一下吧.... xml简述 xml被设计用来传输和存储数据.(html被设计用来显示数据) xml指可扩展标记语言(Extensible Markup Language) xml是一种标记语言,很类似html xml的设计宗旨是传输数据,而非显示数据 xml标签

C#操作XML(读XML,写XML,更新,删除节点,与dataset结合等)【转载】

已知有一个XML文件(bookstore.xml)如下: Corets, Eva 5.95 1.插入节点 往节点中插入一个节点: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 XmlDocument xmlDoc=new XmlDocument(); xmlDoc.Load("bookstore.xml"); XmlNode root=xmlDoc.SelectSingleNode("bookstore");//查找

swift-重写方法和属性、禁止重写

子类可以为继承来的实例方法,类方法,实例属性,或下标提供自己定制的实现.我们把这种行为叫重写. 如果要重写某个特性,你需要在重写定义的前面加上 关键字.这么做,你就表明了你是想提供一个重写 版本,而非错误地提供了一个相同的定义.意外的重写行为可能会导致不可预知的错误,任何缺少 关键 字的重写都会在编译时被诊断为错误. 关键字会提醒 Swift 编译器去检查该类的超类(或其中一个父类)是否有匹配重写版本的声明.这个 检查可以确保你的重写定义是正确的. class Vehicle { var cur

黑马程序员-Java基础-面向对象—继承、构造函数、重写、final、抽象类、接口

第一讲  继承 1.  继承的作用 1) 提高代码复用性: 2) 让类与类之间产生了关系: 2.  java继承特点 1) java只支持单继承,不支持多继承 因为多继承容易带来安全隐患:当多个父类中定义了相同功能,但功能内容不同时,子类对象不确定要运行哪一个. 2) java支持多层继承:可以形成一个继承体系 利用一个继承体系的方法:阅读体系父类,了解共性功能(该体系的基本功能),具体要调用这些基本功能时,需要创建最子类的对象,为什是最子类: 一是:父类有可能不能创建兑现(如,静态类或接口):