Récupération d'informations d'installation à partir d'un domaine d'application
Remarque
Cet article est spécifique au .NET Framework. Cela ne s’applique pas aux implémentations plus récentes de .NET, notamment .NET 6 et versions ultérieures.
Chaque instance d’un domaine d’application se compose des deux propriétés et d’informations AppDomainSetup. Vous pouvez récupérer les informations d’installation à partir d’un domaine d’application à l’aide de la classe System.AppDomain. Cette classe fournit plusieurs membres qui récupèrent les informations de configuration sur un domaine d’application.
Vous pouvez également interroger l’objet AppDomainSetup pour le domaine d’application afin d’obtenir les informations d’installation passées au domaine au moment de sa création.
L’exemple suivant crée un domaine d’application, puis imprime plusieurs valeurs de membre sur la console.
using namespace System;
using namespace System::Reflection;
ref class AppDomain3
{
public:
static void Main()
{
// Create the new application domain.
AppDomain^ domain = AppDomain::CreateDomain("MyDomain", nullptr);
// Output to the console.
Console::WriteLine("Host domain: " + AppDomain::CurrentDomain->FriendlyName);
Console::WriteLine("New domain: " + domain->FriendlyName);
Console::WriteLine("Application base is: " + domain->BaseDirectory);
Console::WriteLine("Relative search path is: " + domain->RelativeSearchPath);
Console::WriteLine("Shadow copy files is set to: " + domain->ShadowCopyFiles);
AppDomain::Unload(domain);
}
};
int main()
{
AppDomain3::Main();
}
using System;
using System.Reflection;
class AppDomain3
{
public static void Main()
{
// Create the new application domain.
AppDomain domain = AppDomain.CreateDomain("MyDomain", null);
// Output to the console.
Console.WriteLine("Host domain: " + AppDomain.CurrentDomain.FriendlyName);
Console.WriteLine("New domain: " + domain.FriendlyName);
Console.WriteLine("Application base is: " + domain.BaseDirectory);
Console.WriteLine("Relative search path is: " + domain.RelativeSearchPath);
Console.WriteLine("Shadow copy files is set to: " + domain.ShadowCopyFiles);
AppDomain.Unload(domain);
}
}
Imports System.Reflection
Class AppDomain3
Public Shared Sub Main()
' Create the new application domain.
Dim domain As AppDomain = AppDomain.CreateDomain("MyDomain", Nothing)
' Output to the console.
Console.WriteLine("Host domain: " + AppDomain.CurrentDomain.FriendlyName)
Console.WriteLine("New domain: " + domain.FriendlyName)
Console.WriteLine("Application base is: " + domain.BaseDirectory)
Console.WriteLine("Relative search path is: " + domain.RelativeSearchPath)
Console.WriteLine("Shadow copy files is set to: " + domain.ShadowCopyFiles)
AppDomain.Unload(domain)
End Sub
End Class
L’exemple suivant définit, puis récupère les informations d’installation pour un domaine d’application. AppDomain.SetupInformation.ApplicationBase
obtient les informations de configuration.
using namespace System;
using namespace System::Reflection;
ref class AppDomain5
{
public:
static void Main()
{
// Application domain setup information.
AppDomainSetup^ domaininfo = gcnew AppDomainSetup();
domaininfo->ApplicationBase = "f:\\work\\development\\latest";
domaininfo->ConfigurationFile = "f:\\work\\development\\latest\\appdomain5.exe.config";
// Creates the application domain.
AppDomain^ domain = AppDomain::CreateDomain("MyDomain", nullptr, domaininfo);
// Write the application domain information to the console.
Console::WriteLine("Host domain: " + AppDomain::CurrentDomain->FriendlyName);
Console::WriteLine("Child domain: " + domain->FriendlyName);
Console::WriteLine();
Console::WriteLine("Application base is: " + domain->SetupInformation->ApplicationBase);
Console::WriteLine("Configuration file is: " + domain->SetupInformation->ConfigurationFile);
// Unloads the application domain.
AppDomain::Unload(domain);
}
};
int main()
{
AppDomain5::Main();
}
using System;
using System.Reflection;
class AppDomain5
{
public static void Main()
{
// Application domain setup information.
AppDomainSetup domaininfo = new AppDomainSetup();
domaininfo.ApplicationBase = "f:\\work\\development\\latest";
domaininfo.ConfigurationFile = "f:\\work\\development\\latest\\appdomain5.exe.config";
// Creates the application domain.
AppDomain domain = AppDomain.CreateDomain("MyDomain", null, domaininfo);
// Write the application domain information to the console.
Console.WriteLine("Host domain: " + AppDomain.CurrentDomain.FriendlyName);
Console.WriteLine("Child domain: " + domain.FriendlyName);
Console.WriteLine();
Console.WriteLine("Application base is: " + domain.SetupInformation.ApplicationBase);
Console.WriteLine("Configuration file is: " + domain.SetupInformation.ConfigurationFile);
// Unloads the application domain.
AppDomain.Unload(domain);
}
}
Imports System.Reflection
Class AppDomain5
Public Shared Sub Main()
' Application domain setup information.
Dim domaininfo As New AppDomainSetup()
domaininfo.ApplicationBase = "f:\work\development\latest"
domaininfo.ConfigurationFile = "f:\work\development\latest\appdomain5.exe.config"
' Creates the application domain.
Dim domain As AppDomain = AppDomain.CreateDomain("MyDomain", Nothing, domaininfo)
' Write the application domain information to the console.
Console.WriteLine("Host domain: " + AppDomain.CurrentDomain.FriendlyName)
Console.WriteLine("Child domain: " + domain.FriendlyName)
Console.WriteLine()
Console.WriteLine("Application base is: " + domain.SetupInformation.ApplicationBase)
Console.WriteLine("Configuration file is: " + domain.SetupInformation.ConfigurationFile)
' Unloads the application domain.
AppDomain.Unload(domain)
End Sub
End Class