mscorlib(4.0.0.0) API with additions
RuntimeEnvironment.cs
1 using System.Reflection;
3 using System.Security;
5 using System.Text;
6 
8 {
10  [ComVisible(true)]
11  public class RuntimeEnvironment
12  {
15  public static string SystemConfigurationFile
16  {
17  [SecuritySafeCritical]
18  get
19  {
20  StringBuilder stringBuilder = new StringBuilder(260);
21  stringBuilder.Append(GetRuntimeDirectory());
22  stringBuilder.Append(AppDomainSetup.RuntimeConfigurationFile);
23  string text = stringBuilder.ToString();
24  new FileIOPermission(FileIOPermissionAccess.PathDiscovery, text).Demand();
25  return text;
26  }
27  }
28 
30  [Obsolete("Do not create instances of the RuntimeEnvironment class. Call the static methods directly on this type instead", true)]
32  {
33  }
34 
35  [MethodImpl(MethodImplOptions.InternalCall)]
36  [SecurityCritical]
37  internal static extern string GetModuleFileName();
38 
39  [MethodImpl(MethodImplOptions.InternalCall)]
40  [SecurityCritical]
41  internal static extern string GetDeveloperPath();
42 
43  [MethodImpl(MethodImplOptions.InternalCall)]
44  [SecurityCritical]
45  internal static extern string GetHostBindingFile();
46 
47  [DllImport("QCall", CharSet = CharSet.Unicode)]
48  [SecurityCritical]
49  [SuppressUnmanagedCodeSecurity]
50  internal static extern void _GetSystemVersion(StringHandleOnStack retVer);
51 
56  public static bool FromGlobalAccessCache(Assembly a)
57  {
58  return a.GlobalAssemblyCache;
59  }
60 
63  [MethodImpl(MethodImplOptions.NoInlining)]
64  [SecuritySafeCritical]
65  public static string GetSystemVersion()
66  {
67  string s = null;
68  _GetSystemVersion(JitHelpers.GetStringHandleOnStack(ref s));
69  return s;
70  }
71 
74  [SecuritySafeCritical]
75  public static string GetRuntimeDirectory()
76  {
77  string runtimeDirectoryImpl = GetRuntimeDirectoryImpl();
78  new FileIOPermission(FileIOPermissionAccess.PathDiscovery, runtimeDirectoryImpl).Demand();
79  return runtimeDirectoryImpl;
80  }
81 
82  [MethodImpl(MethodImplOptions.InternalCall)]
83  [SecurityCritical]
84  internal static extern string GetRuntimeDirectoryImpl();
85 
86  [DllImport("QCall", CharSet = CharSet.Unicode)]
87  [SecurityCritical]
88  [SuppressUnmanagedCodeSecurity]
89  private static extern IntPtr GetRuntimeInterfaceImpl([In] [MarshalAs(UnmanagedType.LPStruct)] Guid clsid, [In] [MarshalAs(UnmanagedType.LPStruct)] Guid riid);
90 
97  [SecurityCritical]
98  [ComVisible(false)]
99  public static IntPtr GetRuntimeInterfaceAsIntPtr(Guid clsid, Guid riid)
100  {
101  return GetRuntimeInterfaceImpl(clsid, riid);
102  }
103 
110  [SecurityCritical]
111  [ComVisible(false)]
112  public static object GetRuntimeInterfaceAsObject(Guid clsid, Guid riid)
113  {
114  IntPtr intPtr = IntPtr.Zero;
115  try
116  {
117  intPtr = GetRuntimeInterfaceImpl(clsid, riid);
118  return Marshal.GetObjectForIUnknown(intPtr);
119  }
120  finally
121  {
122  if (intPtr != IntPtr.Zero)
123  {
124  Marshal.Release(intPtr);
125  }
126  }
127  }
128  }
129 }
FileIOPermissionAccess
Specifies the type of file access requested.
unsafe override string ToString()
Converts the value of this instance to a T:System.String.
static IntPtr GetRuntimeInterfaceAsIntPtr(Guid clsid, Guid riid)
Returns the specified interface on the specified class.
Definition: __Canon.cs:3
static int Release(IntPtr pUnk)
Decrements the reference count on the specified interface.
Provides a collection of static methods that return information about the common language runtime env...
static string GetRuntimeDirectory()
Returns the directory where the common language runtime is installed.
static string SystemConfigurationFile
Gets the path to the system configuration file.
Represents assembly binding information that can be added to an instance of T:System....
Represents a globally unique identifier (GUID).To browse the .NET Framework source code for this type...
Definition: Guid.cs:14
static string GetSystemVersion()
Gets the version number of the common language runtime that is running the current process.
StringBuilder Append(char value, int repeatCount)
Appends a specified number of copies of the string representation of a Unicode character to this inst...
UnmanagedType
Identifies how to marshal parameters or fields to unmanaged code.
Definition: UnmanagedType.cs:7
Represents an assembly, which is a reusable, versionable, and self-describing building block of a com...
Definition: Assembly.cs:22
A platform-specific type that is used to represent a pointer or a handle.
Definition: IntPtr.cs:14
virtual bool GlobalAssemblyCache
Gets a value indicating whether the assembly was loaded from the global assembly cache.
Definition: Assembly.cs:227
Provides a collection of methods for allocating unmanaged memory, copying unmanaged memory blocks,...
Definition: Marshal.cs:15
MethodImplOptions
Defines the details of how a method is implemented.
CharSet
Dictates which character set marshaled strings should use.
Definition: CharSet.cs:7
Represents a mutable string of characters. This class cannot be inherited.To browse the ....
static object GetRuntimeInterfaceAsObject(Guid clsid, Guid riid)
Returns an instance of a type that represents a COM object by a pointer to its IUnknown interface.
void Demand()
Forces a T:System.Security.SecurityException at run time if all callers higher in the call stack have...
RuntimeEnvironment()
Initializes a new instance of the T:System.Runtime.InteropServices.RuntimeEnvironment class.
static readonly IntPtr Zero
A read-only field that represents a pointer or handle that has been initialized to zero.
Definition: IntPtr.cs:20
static bool FromGlobalAccessCache(Assembly a)
Tests whether the specified assembly is loaded in the global assembly cache.
Controls the ability to access files and folders. This class cannot be inherited.
static object GetObjectForIUnknown(IntPtr pUnk)
Returns an instance of a type that represents a COM object by a pointer to its IUnknown interface.