Compartilhar via


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
System_CAPS_pubmethod RuntimeEnvironment()

Obsoleto.Inicializa uma nova instância da classe RuntimeEnvironment.

Propriedades

Nome Descrição
System_CAPS_pubpropertySystem_CAPS_static SystemConfigurationFile

Obtém o caminho para o arquivo de configuração do sistema.

Métodos

Nome Descrição
System_CAPS_pubmethod Equals(Object)

Determina se o objeto especificado é igual ao objeto atual.(Herdado de Object.)

System_CAPS_protmethod 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.)

System_CAPS_pubmethodSystem_CAPS_static FromGlobalAccessCache(Assembly)

Testa se o assembly especificado é carregado no cache de assembly global.

System_CAPS_pubmethod GetHashCode()

Serve como a função de hash padrão.(Herdado de Object.)

System_CAPS_pubmethodSystem_CAPS_static GetRuntimeDirectory()

Retorna o diretório no qual o Common Language Runtime está instalado.

System_CAPS_pubmethodSystem_CAPS_static GetRuntimeInterfaceAsIntPtr(Guid, Guid)

Retorna a interface especificada na classe especificada.

System_CAPS_pubmethodSystem_CAPS_static GetRuntimeInterfaceAsObject(Guid, Guid)

Retorna uma instância de um tipo que representa um objeto COM de um ponteiro para sua interface IUnknown.

System_CAPS_pubmethodSystem_CAPS_static GetSystemVersion()

Obtém o número de versão do Common Language Runtime que executa o processo atual.

System_CAPS_pubmethod GetType()

Obtém o Type da instância atual.(Herdado de Object.)

System_CAPS_protmethod MemberwiseClone()

Cria uma cópia superficial do Object atual.(Herdado de Object.)

System_CAPS_pubmethod 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