Classe RuntimeEnvironment
Dica
The .NET API Reference documentation has a new home. Visit the .NET API Browser on docs.microsoft.com to see the new experience.
Fornece uma coleção de métodos static que retornam informações sobre o ambiente de Common Language Runtime.
Namespace: System.Runtime.InteropServices
Assembly: mscorlib (em mscorlib.dll)
Hierarquia de Herança
System.Object
System.Runtime.InteropServices.RuntimeEnvironment
Sintaxe
[ComVisibleAttribute(true)]
public class RuntimeEnvironment
[ComVisibleAttribute(true)]
public ref class RuntimeEnvironment
[<ComVisibleAttribute(true)>]
type RuntimeEnvironment = class end
<ComVisibleAttribute(True)>
Public Class RuntimeEnvironment
Construtores
Nome | Descrição | |
---|---|---|
RuntimeEnvironment() | Obsoleto.Inicializa uma nova instância da classe RuntimeEnvironment. |
Propriedades
Nome | Descrição | |
---|---|---|
SystemConfigurationFile | Obtém o caminho para o arquivo de configuração do sistema. |
Métodos
Nome | Descrição | |
---|---|---|
Equals(Object) | Determina se o objeto especificado é igual ao objeto atual.(Herdado de Object.) |
|
Finalize() | Permite que um objeto tente liberar recursos e executar outras operações de limpeza antes de ser recuperado pela coleta de lixo.(Herdado de Object.) |
|
FromGlobalAccessCache(Assembly) | Testa se o assembly especificado é carregado no cache de assembly global. |
|
GetHashCode() | Serve como a função de hash padrão.(Herdado de Object.) |
|
GetRuntimeDirectory() | Retorna o diretório no qual o Common Language Runtime está instalado. |
|
GetRuntimeInterfaceAsIntPtr(Guid, Guid) | Retorna a interface especificada na classe especificada. |
|
GetRuntimeInterfaceAsObject(Guid, Guid) | Retorna uma instância de um tipo que representa um objeto COM de um ponteiro para sua interface IUnknown. |
|
GetSystemVersion() | Obtém o número de versão do Common Language Runtime que executa o processo atual. |
|
GetType() | ||
MemberwiseClone() | Cria uma cópia superficial do Object atual.(Herdado de Object.) |
|
ToString() | Retorna uma cadeia de caracteres que representa o objeto atual.(Herdado de Object.) |
Exemplos
Este exemplo mostra como chamar muitos dos métodos definidos pela RuntimeEnvironment classe.
using System;
using System.Reflection;
using System.Runtime.InteropServices;
public sealed class App
{
static void Main()
{
// Show whether the EXE assembly was loaded from the GAC or from a private subdirectory.
Assembly assem = typeof(App).Assembly;
Console.WriteLine("Did the {0} assembly load from the GAC? {1}",
assem, RuntimeEnvironment.FromGlobalAccessCache(assem));
// Show the path where the CLR was loaded from.
Console.WriteLine("Runtime directory: {0}", RuntimeEnvironment.GetRuntimeDirectory());
// Show the CLR's version number.
Console.WriteLine("System version: {0}", RuntimeEnvironment.GetSystemVersion());
// Show the path of the machine's configuration file.
Console.WriteLine("System configuration file: {0}", RuntimeEnvironment.SystemConfigurationFile);
}
}
// This code produces the following output.
//
// Did the RuntimeEnvironment, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
// assembly load from the GAC? False
// Runtime directory: C:\WINDOWS\Microsoft.NET\Framework\v2.0.40607\
// System version: v2.0.40607
// System configuration file: C:\WINDOWS\Microsoft.NET\Framework\v2.0.40607\config\
// machine.config
Imports System.Reflection
Imports System.Runtime.InteropServices
Public NotInheritable Class App
Shared Sub Main()
' Show whether the EXE assembly was loaded from the GAC or from a private subdirectory.
Dim assem As Assembly = GetType(App).Assembly
Console.WriteLine("Did the {0} assembly load from the GAC? {1}",
assem, RuntimeEnvironment.FromGlobalAccessCache(assem))
' Show the path where the CLR was loaded from.
Console.WriteLine("Runtime directory: {0}", RuntimeEnvironment.GetRuntimeDirectory())
' Show the CLR's version number.
Console.WriteLine("System version: {0}", RuntimeEnvironment.GetSystemVersion())
' Show the path of the machine's configuration file.
Console.WriteLine("System configuration file: {0}", RuntimeEnvironment.SystemConfigurationFile)
End Sub
End Class
' This code produces the following output.
'
' Did the RuntimeEnvironment, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
' assembly load from the GAC? False
' Runtime directory: C:\WINDOWS\Microsoft.NET\Framework\v2.0.40607\
' System version: v2.0.40607
' System configuration file: C:\WINDOWS\Microsoft.NET\Framework\v2.0.40607\config\
' machine.config
using namespace System;
using namespace System::Reflection;
using namespace System::Runtime::InteropServices;
int main()
{
// Show whether the EXE assembly was loaded from the GAC or from a
// private subdirectory.
Console::WriteLine("Did the {0} assembly load from the GAC? {1}",
Assembly::GetExecutingAssembly(),
RuntimeEnvironment::FromGlobalAccessCache(
Assembly::GetExecutingAssembly()));
// Show the path where the CLR was loaded from.
Console::WriteLine("Runtime directory: {0}",
RuntimeEnvironment::GetRuntimeDirectory());
// Show the CLR's version number.
Console::WriteLine("System version: {0}",
RuntimeEnvironment::GetSystemVersion());
// Show the path of the machine's configuration file.
Console::WriteLine("System configuration file: {0}",
RuntimeEnvironment::SystemConfigurationFile);
}
// This code produces the following output.
//
// Did the RuntimeEnvironment, Version=0.0.0.0, Culture=neutral,
// PublicKeyToken=null
// assembly load from the GAC? False
// Runtime directory: C:\WINDOWS\Microsoft.NET\Framework\v2.0.40607\
// System version: v2.0.40607
// System configuration file:
// C:\WINDOWS\Microsoft.NET\Framework\v2.0.40607\config\machine.config
Informações de Versão
.NET Framework
Disponível desde 1.1
Acesso thread-safe
Quaisquer membros estáticos públicos ( Compartilhado no Visual Basic) desse tipo são thread-safe. Não há garantia de que qualquer membro de instância seja thread-safe.
Confira Também
Namespace System.Runtime.InteropServices
Retornar ao início