Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

OpenExeConfiguration has 2 overloads:

OpenMappedExeConfiguration has only 1 prototype:

It seems both (2) and (3) can be used to open a specific config file rather than the default app.config file.

So what's the difference between them? When to use which?

Why do we seperate the UserLevel and Config File Location in (1) and (2), but combine them in (3)?

Thanks for any replies.

Update

I know that Microsoft always like to do things in more than one ways. But it should do it for a reason. Any body know the reason in my question? Do we need a bounty ;) ?

See Question&Answers more detail:os

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

1 Answer

The difference is explained in the ultimate .NET config resource - Cracking the Mysteries of .NET 2.0 Configuration:

OpenExeConfiguration (String)

will append ".config" to the filename you provide and load that configuration file. It's important to note that OpenExeConfiguration(string exePath) is a very misleading method, as the filename does not have to be the filename of the .exe that is running [...] By providing a filename other than the EXE filename, an alternate *.config file can be opened.

OpenExeConfiguration (ConfigurationUserLevel)

The second method, OpenExeConfiguration(ConfigurationUserLevel level) will load the appropriate configuration file for the specified configuration level. Configuration levels, available in the Exe context, allow you to specify whether you want exe, roaming user, or local user configuration [...] Remember that configuration is hierarchical and merged. When requesting roaming or local user configuration, that level up through machine.config are merged, resulting in the complete configuration accessible by your application for the given user level.

OpenMappedExeConfiguration(), OpenMappedMachineConfiguration()

Unlike the OpenExeConfiguration() methods, which make several assumptions about where your configuration files reside, OpenMappedExeConfiguration() and OpenMappedMachineConfiguration() allow you to explicitly specify where your *.config files reside on disk. Using these methods, you can load an alternate machine.config, load User.config files from the locations of your own choosing (vs. letting the .NET framework decide on some convoluted path), etc. When accessing machine.config, a custom version is not required, OpenMachineConfiguration() should be used instead.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...