C# 应用程序和配置设置
我以前从未使用过 Settings
类,但我在 CodeProject 上找到了一些我目前正在阅读的文章(例如 http://www.codeproject.com/KB/cs/PropertiesSettings.aspx),但到目前为止我还没有看到如何保存 string
下次启动应用程序后获取它的数组。
例如,我的应用程序有多个 FileSystemWatcher 实例,每个实例都连接几个其他目录(例如,一个 FSW 实例正在监视一个目录的更改,当发生更改时,它将某些文件复制到其他几个目录) ,所以我将有一个 string
数组,其中包含表示 FSW 实例的监视路径,以及每个路径的 string
数组,表示受影响的目录。
我的问题是,我应该使用什么(Settings
类或其他类),以及如何使用它来存储可变数量的 string
数组的应用程序配置?强调的是我可以很快使用的东西,因为我没有太多时间来制作自定义类(但如果我找不到解决方案,则必须这样做)或深入研究一些晦涩的黑客。 任何教程链接、代码片段都会非常有帮助。
谢谢。
I never used Settings
class before but I found some articles on CodeProject which I'm currently reading (for example http://www.codeproject.com/KB/cs/PropertiesSettings.aspx) but so far I didn't see how to save string
array for getting it after application is started next time.
For example my application has several FileSystemWatcher
instances, with each instance several other directories are connected (for example one FSW instance is monitoring one directory for a change and when it happens it copies some file to several other directories), so I would have one string
array with watched paths representing FSW instances, and string
array for each of those paths, representing directories that are affected.
My question is, what should I use (Settings
class or something else), and how should I use that for storing application configuration that is variable number of string
arrays? Emphasize is on something I could use very soon as I don't have too much time to make custom class (but would have to if I cannot find solution) or dig into some obscure hacks.
Any tutorial link, code snippet would be very helpful.
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
为什么不使用配置文件呢?我有一组像你一样的 FileSystemWatchers,只是使用 自定义配置添加了一组路径部分。认为这需要您滚动一个类来扩展配置类,但我认为您无法击败这种方法。
不过,如果您想要一个清晰简单的破解并且不想被自定义配置部分/元素/集合所困扰。只需使用快速简单的 AppSettings 技巧即可。 XD
从代码中获取它。
有点丑,我知道。自定义配置效果最好。
Why not use a config file instead? I had a set of FileSystemWatchers like yours and just added a set of paths using custom config sections. Thought that requires you rolling a class to extending the Configuration classes, but I think that you can't beat that approach.
Though if you want a clear easy hack and don't want to get bothered with the Custom Config Sections/Elements/Collections. Just use a quick and easy AppSettings hack. XD
Getting it from code.
Tad ugly, I know. Custom Config works best.