IVsApplicationConfiguration.QueryEditConfiguration 方法

确定是否可以修改配置文件。

命名空间:  Microsoft.VisualStudio.ManagedInterfaces9
程序集:  Microsoft.VisualStudio.ManagedInterfaces.WCF(在 Microsoft.VisualStudio.ManagedInterfaces.WCF.dll 中)

语法

声明
Function QueryEditConfiguration As Boolean
bool QueryEditConfiguration()
bool QueryEditConfiguration()
abstract QueryEditConfiguration : unit -> bool
function QueryEditConfiguration() : boolean

返回值

类型:Boolean
true ,如果能修改配置文件;否则 false。

备注

QueryEditConfiguration 方法调用 QueryEditFiles 方法确定配置文件是否可编辑。 如果文件不存在,默认配置文件 (如果项目的根级别) 或空的配置文件中创建。

备注

如果该项目在源代码管理下,此事件将导致项目文件签出和中重新加载的项目。

如果方法生成添加到项目的配置文件,所有先前返回的配置对象 null。 注册 ConfigurationChanged 事件的处理程序中的客户端上通知文件被添加。

示例

下面的代码示例演示如何使用 QueryEditConfiguration 方法确定配置文件是否可编辑。

/// 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 安全性

请参阅

参考

IVsApplicationConfiguration 接口

Microsoft.VisualStudio.ManagedInterfaces9 命名空间