开发者

C# Way to serialize List<string> in settings containing any character (Regex/xml)

I am looking for a neat/clean way to store a list of strings into a C# settings file. As far as I can work out, you can't store List objects into these settings, so basically it needs to be converted to a string. For example, say I have a list of names:

  • NameA
  • Name;B
  • Complex, Weird, Name
  • Name"nickname"Person

i.e. I am trying to demonstrate a list of names which can possibly contain any character. Does anyone have any recommendations for a neat format + Regex to read it tha开发者_如何学Ct can handle any character? Or possibly an easy way to serialize a List<string>?

Currently, I am saving them as a simple command delimited string which works fine so long as you are careful with the names (can't have commas), but is destined to break down the line.


You can select the type of your setting entry as

System.Collections.Specialized.StringCollection

from the Properties.Settings tab.

This will be translated into your config file as something like

 <ArrayOfString xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xmlns:xsd="http://www.w3.org/2001/XMLSchema">
  <string>string1</string>
  <string>string2</string>
 </ArrayOfString>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜