Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
332 views
in Technique[技术] by (71.8m points)

.net - Can you have a generic List(of T) in your settings file?

In my settings file, I would like to have one setting that is of the type List(of Myclass).... I can't find anything on the net that does this. Is it possible?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I agree that Meta-Knight's inheritance solution is best, however it is possible to do this by manually editing the setting XML file. In Solution Explorer go to: Solution > Project > Properties > Settings.settings. Right-click on Settings.settings and choose "Open With". Select "XML (Text) Editor". Then insert the following inside <Settings>:

<Setting Name="TestGenericList" Type="System.Collections.Generic.List&lt;int&gt;" Scope="User">
  <Value Profile="(Default)" />
</Setting>

save, and it works.

Unfortunately it doesn't appear to work with generic types requiring two or more types, since the comma is not allowed in that attribute. Even entity-encoding it (&#x002C;) didn't help.

The following causes an error "Illegal characters in path" when you go to edit the settings file in the settings designer:

<Setting Name="TestGenericDictionary" Type="System.Collections.Generic.Dictionary&lt;string&#x002C;string&gt;" Scope="User">
  <Value Profile="(Default)" />
</Setting>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...