开发者

Building a dynamically generated configuration UI using reflection on .NET Config Datatypes

Has anyone got any experience with / attempted to do this?

We have some reasonably complex XML config for our .NET application and were thinking it would be nice if we could use our config object hierarchy to dynamically build a UI, using reflection and attributes/meta-data from the properties on these object开发者_JAVA技巧s to present options to user to produce the configuration.

It would be nice to make this quite generic, so we can provide it with any .NET XML config object (within reason) and it would reflect on it and allow it to be populated.


You need to think about exactly what Config files in .NET are for. They are a place for defining the differences between different deployments of your application. So when you talk about dynamically altering config based on coded logic, I think you might have it the wrong way round. It is your code that should be taking its direction from settings injected via configuration.

It seems you are looking to build some kind of config editor? Why do this when Visual Studio has two built in? The Edit Window and the various Configuration Editors, ASP.NET configuration Editor, Microsoft Service Configuration Editor etc.

In my experience, the differences between web or app.config in a Dev environment vs a Test environment vs a production environment will typically differ by just a few settings, such as Connection strings, AppSettings, Message Queue addresses, Service Endpoints, Log4Net settings etc.

Okay, quite a few settings, but in each block of config, there is usually only one or two attributes that differ from environment to environment. The exception to this is IOC config, such as Spring.NET, CastleWinsor or Unity. But even then, these are often exactly the same from environment to environment.

I would encourage you to go away and think about this for a bit. Think about the actual problem that you are trying to solve. Perhaps you are in need of some database driven workflow? I don't know.

I just know that config should not be driven by runtime code. It is a deployment and build-time thing.

Having said that, there are tools such as ConfigGen, which makes generating environment-specific configuration a breeze. Check it out when this is really what you need.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜