Método IVsApplicationConfiguration.QueryEditConfiguration
Determina se um arquivo de configuração pode ser modificado.
Namespace: Microsoft.VisualStudio.ManagedInterfaces9
Assembly: Microsoft.VisualStudio.ManagedInterfaces.WCF (em Microsoft.VisualStudio.ManagedInterfaces.WCF.dll)
Sintaxe
'Declaração
Function QueryEditConfiguration As Boolean
bool QueryEditConfiguration()
bool QueryEditConfiguration()
abstract QueryEditConfiguration : unit -> bool
function QueryEditConfiguration() : boolean
Valor de retorno
Tipo: Boolean
true Se o arquivo de configuração pode ser modificado. Caso contrário, false.
Comentários
O QueryEditConfiguration chamadas de método de QueryEditFiles método para determinar se o arquivo de configuração pode ser editado. Se o arquivo não existir, será criado um arquivo de configuração padrão (se estiver no nível da raiz do projeto) ou um arquivo de configuração vazio.
Dica
Se o projeto estiver sob controle de origem, esta ação fará com que o arquivo de projeto check-out e o projeto ser recarregado.
Se o método resulta em um arquivo de configuração que está sendo adicionado ao projeto, qualquer objeto de configuração retornadas anteriormente é processado inválido. Os clientes que se inscreveram para um manipulador para o ConfigurationChanged evento será notificado de que o arquivo foi adicionado.
Exemplos
O exemplo de código a seguir demonstra como usar o QueryEditConfiguration método para determinar se um arquivo de configuração pode ser editado.
/// 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();
}
}
}
Segurança do .NET Framework
- Confiança total para o chamador imediato. O membro não pode ser usado por código parcialmente confiável. Para obter mais informações, consulte Usando bibliotecas de código parcialmente confiável.