.NET 动态序列化转换
我有一个节点,其中包含 xml 文件中的分隔值,我将其反序列化(System.Xml.Serialization)为一个类。
这是 XML 数据元素节点的示例:
<Data>1,2,3,4,8,11<Data>
是否可以在反序列化过程中拆分整数数据,以便将数据字符串转换为属性列表,如下所示:
List<int> Data {get; set;}
I have a node that contains delimited values in an xml file which I am deserializing(System.Xml.Serialization) to a class.
This is a sample of the XML data element node:
<Data>1,2,3,4,8,11<Data>
Is it possible to split the integer data during the deserialization process so that the string of data gets converted into a list of property like the following:
List<int> Data {get; set;}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我建议使用 LINQ to XML 进行序列化,但如果您使用 System.Xml.Serialization,则可以通过对
String
属性使用自定义 setter 来执行此操作,该属性会拆分字符串并填充List
属性。在 Munim 的编辑之后
在 Minim 添加通用
之后,setter 应该是这样的:I'd recommend using LINQ to XML for serialization, but if you use
System.Xml.Serialization
you could perform this by using a custom setter for aString
property that splits the string and fills theList
property.AFTER Munim's EDIT
After Minim added the generic
<int>
, the setter should be like this: