Compartir a través de


Clase RuntimeEnvironment

 

Publicado: octubre de 2016

Proporciona una colección de static métodos que devuelven información sobre el entorno de common language runtime.

Espacio de nombres:   System.Runtime.InteropServices
Ensamblado:  mscorlib (en mscorlib.dll)

Jerarquía de herencia

System.Object
  System.Runtime.InteropServices.RuntimeEnvironment

Sintaxis

[ComVisibleAttribute(true)]
public class RuntimeEnvironment
[ComVisibleAttribute(true)]
public ref class RuntimeEnvironment 
[<ComVisibleAttribute(true)>]
type RuntimeEnvironment = class end
<ComVisibleAttribute(True)>
Public Class RuntimeEnvironment

Constructores

Nombre Descripción
System_CAPS_pubmethod RuntimeEnvironment()

Obsoleto. Inicializa una nueva instancia de la clase RuntimeEnvironment.

Propiedades

Nombre Descripción
System_CAPS_pubpropertySystem_CAPS_static SystemConfigurationFile

Obtiene la ruta de acceso al archivo de configuración del sistema.

Métodos

Nombre Descripción
System_CAPS_pubmethod Equals(Object)

Determina si el objeto especificado es igual al objeto actual.(Heredado de Object).

System_CAPS_protmethod Finalize()

Permite que un objeto intente liberar recursos y realizar otras operaciones de limpieza antes de que sea reclamado por la recolección de elementos no utilizados.(Heredado de Object).

System_CAPS_pubmethodSystem_CAPS_static FromGlobalAccessCache(Assembly)

Comprueba si el ensamblado especificado se carga en la caché global de ensamblados.

System_CAPS_pubmethod GetHashCode()

Sirve como la función hash predeterminada.(Heredado de Object).

System_CAPS_pubmethodSystem_CAPS_static GetRuntimeDirectory()

Devuelve el directorio donde está instalado common language runtime.

System_CAPS_pubmethodSystem_CAPS_static GetRuntimeInterfaceAsIntPtr(Guid, Guid)

Devuelve la interfaz especificada en la clase especificada.

System_CAPS_pubmethodSystem_CAPS_static GetRuntimeInterfaceAsObject(Guid, Guid)

Devuelve una instancia de un tipo que representa un objeto COM por un puntero a su IUnknown interfaz.

System_CAPS_pubmethodSystem_CAPS_static GetSystemVersion()

Obtiene el número de versión de common language runtime que se está ejecutando el proceso actual.

System_CAPS_pubmethod GetType()

Obtiene el Type de la instancia actual.(Heredado de Object).

System_CAPS_protmethod MemberwiseClone()

Crea una copia superficial del Object actual.(Heredado de Object).

System_CAPS_pubmethod ToString()

Devuelve una cadena que representa el objeto actual.(Heredado de Object).

Ejemplos

Este ejemplo muestra cómo llamar a muchos de los métodos definidos por el RuntimeEnvironment clase.

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

Información de versión

.NET Framework
Disponible desde 1.1

Seguridad para subprocesos

Cualquier miembro ( Compartido en Visual Basic) estático público de este tipo es seguro para subprocesos. No se garantiza que los miembros de instancia sean seguros para subprocesos.

Ver también

Espacio de nombres System.Runtime.InteropServices

Volver al principio