jjzjj

XmlArrayItem

全部标签

c# - 将 XML 反序列化为不同元素上的相同类型的子元素

更新:已解决-见下文!反序列化包含网络节点的xml文件时,在处理子元素时似乎出现了问题。我有以下父(根)类:NetworkCollection[Serializable,XmlRoot("networks"),XmlType("networks")]publicclassNetworkCollection:CollectionBase,IBindingList{//...}与子类:网络[Serializable,XmlRoot("network"),XmlType("network")]publicclassNetwork{[XmlAttribute("id")]publicstrin

c# - 如何为 List<Custom> 实现设置 XmlArrayItem 元素名称?

我想创建一个自定义的XML结构,如下所示:我已经创建了List的实现,以便能够执行此操作。我的代码如下:[XmlRootAttribute(ElementName="Hotels")]publicclassHotelList:List因为List包含的类不是Hotel而是HotelBasic我的xml是这样的如何在不必实现ISerializable或IEnumerable的情况下解决此问题? 最佳答案 [XmlArray("Hotels")][XmlArrayItem(typeof(Hotel),ElementName="Hotel

c# - 如何为 List<Custom> 实现设置 XmlArrayItem 元素名称?

我想创建一个自定义的XML结构,如下所示:我已经创建了List的实现,以便能够执行此操作。我的代码如下:[XmlRootAttribute(ElementName="Hotels")]publicclassHotelList:List因为List包含的类不是Hotel而是HotelBasic我的xml是这样的如何在不必实现ISerializable或IEnumerable的情况下解决此问题? 最佳答案 [XmlArray("Hotels")][XmlArrayItem(typeof(Hotel),ElementName="Hotel

c# - 在可序列化的 C# 类上使用不带 XmlArray 的 XmlArrayItem 属性

我想要以下格式的XML:.........我正在尝试创建一个类Configuration有[Serializable]属性。要序列化凭据节点,我有以下内容:[XmlArray("configuration")][XmlArrayItem("credentials",typeof(CredentialsSection))]publicListCredentials{get;set;}但是,当我将其序列化为XML时,XML的格式如下:.........如果我删除[XmlArray("configuration")]行,我得到以下信息:.........如何使用多个以我想要的方式序列化它单个