gpt4 book ai didi

c# - OpenMappedExeConfiguration 与 OpenExeConfiguration

转载 作者:IT王子 更新时间:2023-10-29 04:12:47 25 4
gpt4 key购买 nike

OpenExeConfiguration 有 2 个重载:

OpenMappedExeConfiguration 只有 1 个原型(prototype):

似乎 (2) 和 (3) 都可以用来打开特定的配置文件,而不是默认的 app.config 文件。

那么它们有什么区别呢?什么时候使用哪个?

为什么我们在(1)和(2)中将UserLevelConfig File Location分开,而在(3)中将它们合并?

感谢您的任何回复。

更新

我知道微软总是喜欢以不止一种方式做事。但它应该这样做是有原因的。任何人都知道我的问题的原因吗?我们需要赏金 ;) 吗?

最佳答案

差异在最终的 .NET 配置资源中进行了解释 - Cracking the Mysteries of .NET 2.0 Configuration :

OpenExeConfiguration(字符串)

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.

关于c# - OpenMappedExeConfiguration 与 OpenExeConfiguration,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3912727/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com