开发者

What are some ways to have config files in C#?

I love the way Python does it, such that you can h开发者_运维问答ave a readable config file within a .py file itself.

This config file is meant for developers only so it doesn't have to be user friendly. What methods can I use to store verbose information?

Thanks!


In .NET we use separate .config files. Data can be read with the ConfigurationManager class.


in .NET its even easier! using system.configuration to read sections from app.config file.

msdn: http://msdn.microsoft.com/en-us/library/system.configuration.configurationmanager.aspx

simple example: http://www.dotnetspider.com/resources/21709-Reading-value-from-App-Config-C-Windows.aspx

Hec


I think the article Using Settings in C# in the MSDN is what you're looking for.


It's not the standard way, but you can use the IronPython interpreter and have a readable .py config file in .NET, too. The advantage over normal XML-configuration files is that a IronPython config file can contain any code, so it can do things like e.g. loop over all files or contain if-else clauses to use different configuration options depending on e.g. the operating system version.


In addition to external config files, you could use a DSL in C# to configure the system, much like is common in things like ASP.NET MVC and/or StructureMap registration.

Of course, if you like the python approach you could run a py script via IronPython to configure your system with a bit less xml. This would avoid the need to recompile, while allowing a code-based config script.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜