本文介绍了[UWP] [VB]使用Xml数组作为属性时的分隔符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 这听起来像一个毫无意义的问题,但我想知道在将整数数组序列化为属性时如何使XmlSerializer使用逗号而不是空格。我目前在Class I序列化中有以下内容: < XmlAttribute()> Public Property Routes()As Integer() 但是,这给了我类似以下内容的属性 在Xml中: Routes =" 0 2 10 8 0 0 0" 但我真正想要的是以下内容: Routes =" 0, 2,10,8,0,0,0" 您可能会问为什么这对我来说如此重要,答案是因为正在为应用程序读取和创建Xml我无法控制。当然,我可以在String和Integer()之间手动转换,但这看起来应该是不必要的。 我当然也可以实现IXmlSerializable,但是再一次看起来应该是不必要的。因为数组是Integer(),我显然知道使用的唯一字符将是数字和分隔符,所以如果有一种方法(在读取之后和写入之前)通过使用 手动编辑属性值。替换("",",",")或  .Replace(",","""),这也很简单,但我不知道我会把它放在哪里(at至少没有添加更复杂的代码,例如IXmlSerializable,这是我想要避免的)。有任何想法吗?谢谢。 Nathan Sokalski [email protected] http://www.nathansokalski.com/解决方案 Hello Nathan Sokalski, 也许,您可以尝试使用字符串的另一个属性来格式化您所描述的"路径"。 Private _Routes As Integer()< XmlAttribute()> Public ReadOnly Property Routes()As String Get 返回String.Join(",",_ Routes) End Get End Property 最好的问候, Xavier Eoro This will sound like a pointless question, but I want to know how to make the XmlSerializer use commas instead of spaces when serializing an array of integers as an attribute. I currently have the following in the Class I am serializing:<XmlAttribute()> Public Property Routes() As Integer()However, this gives me something like the following as the attribute in the Xml:Routes="0 2 10 8 0 0 0"But what I really want is the following:Routes="0,2,10,8,0,0,0"You may ask why this is so important to me, and the answer is because the Xml is being read from and created for an app that I do not have control over. I could, of course, manually convert between a String and Integer(), but that seems like it should be unnecessary. I could also, of course, implement IXmlSerializable, but once again, it seems like that should be unnecessary. Because the array is Integer(), I obviously know that the only characters used will be digits and the delimiter, so if there was a way to (after reading and before writing) manually edit the attribute value by using .Replace(" ", ",") or .Replace(",", " "), that would be pretty simple too, but I don't know where I would put that (at least not without adding more complicated code such as IXmlSerializable, which is what I want to avoid). Any ideas? Thanks.Nathan Sokalski [email protected] http://www.nathansokalski.com/ 解决方案 Hello Nathan Sokalski,Maybe, you could try to use another property of string to format the "Routes" as you described.Private _Routes As Integer()<XmlAttribute()> Public ReadOnly Property Routes() As StringGetReturn String.Join(",", _Routes)End GetEnd PropertyBest Regards,Xavier Eoro 这篇关于[UWP] [VB]使用Xml数组作为属性时的分隔符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!
10-29 03:09