加载特定层次结构/itemid 的配置。
命名空间: Microsoft.VisualStudio.ManagedInterfaces9
程序集: Microsoft.VisualStudio.ManagedInterfaces.WCF(在 Microsoft.VisualStudio.ManagedInterfaces.WCF.dll 中)
语法
声明
Function LoadConfiguration As Configuration
Configuration LoadConfiguration()
Configuration^ LoadConfiguration()
abstract LoadConfiguration : unit -> Configuration
function LoadConfiguration() : Configuration
返回值
类型:Configuration
Configuration 对象。
异常
异常 | 条件 |
---|---|
ConfigurationException | 配置层次结构处于一种可加载状态。 |
备注
从此方法返回的配置实例才有效,直至下一个 ConfigurationChanged 事件生成。
示例
下面的代码示例演示如何使用 LoadConfiguration 方法修改配置文件。
/// Make sure that our custom WSDL importer extension is registered in /// the Metadata section of the configuration file for the current
/// project hierarchy and serviceProvider that gives access to required
/// services.
private static void EnsureCustomWsdlImporterRegistered
(IVsHierarchy hierarchy, IServiceProvider serviceProvider)
{
/// The IVsApplicationConfigurationManager service returns a
/// System.Configuration.Configuration object corresponding to
/// the given project's app.config or web.config file.
IVsApplicationConfigurationManager cfgMgr =
serviceProvider.GetService(typeof(IVsApplicationConfigurationManager))
as IVsApplicationConfigurationManager;
// Return the current application's configuration file by using
// the IVsApplicationConfiguration APIs. Make sure that the
// instance that is returned is disposed of correctly in order
// to clean up any event hooks or docdatas.
using (IVsApplicationConfiguration appCfg =
cfgMgr.GetApplicationConfiguration(hierarchy,
Microsoft.VisualStudio.VSConstants.VSITEMID_ROOT))
{
System.Configuration.Configuration cfg =
appCfg.LoadConfiguration();
// Check the file out from Source Code Control if it
// exists.
appCfg.QueryEditConfiguration();
/// After a System.Configuration.Configuration object
/// exists, use the"normal" .NET Framework configuration
/// APIs to return the sections that you want to modify.
ServiceModelSectionGroup sg =
ServiceModelSectionGroup.GetSectionGroup(cfg);
Type importerType = typeof(BindingPickerWsdlImportExtension);
if (!IsWsdlImporterRegistered(sg, importerType))
{
// If our custom WSDL importer is not registered, add
// it to the application's configuration file.
sg.Client.Metadata.WsdlImporters.Add(new
WsdlImporterElement(importerType));
cfg.Save();
}
}
}
.NET Framework 安全性
- 对直接调用方的完全信任。此成员不能由部分信任的代码使用。有关详细信息,请参阅通过部分受信任的代码使用库。