Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches

◆ GetEnvironmentVariables() [1/2]

static unsafe IDictionary System.Environment.GetEnvironmentVariables ( )
inlinestatic

Definition at line 908 of file Environment.cs.

909 {
910 char* environmentStringsW = Interop.Kernel32.GetEnvironmentStringsW();
911 if (environmentStringsW == null)
912 {
913 throw new OutOfMemoryException();
914 }
915 try
916 {
917 Hashtable hashtable = new Hashtable();
918 char* ptr = environmentStringsW;
919 while (true)
920 {
921 ReadOnlySpan<char> span = MemoryMarshal.CreateReadOnlySpanFromNullTerminated(ptr);
922 if (span.IsEmpty)
923 {
924 break;
925 }
926 int num = span.IndexOf('=');
927 if (num > 0)
928 {
929 string key = new string(span.Slice(0, num));
930 string value = new string(span.Slice(num + 1));
931 try
932 {
933 hashtable.Add(key, value);
934 }
935 catch (ArgumentException)
936 {
937 }
938 }
939 ptr += span.Length + 1;
940 }
941 return hashtable;
942 }
943 finally
944 {
945 Interop.BOOL bOOL = Interop.Kernel32.FreeEnvironmentStringsW(environmentStringsW);
946 }
947 }
static unsafe char * GetEnvironmentStringsW()
static unsafe BOOL FreeEnvironmentStringsW(char *lpszEnvironmentBlock)
virtual void Add(object key, object? value)
Definition Hashtable.cs:676
static unsafe ReadOnlySpan< char > CreateReadOnlySpanFromNullTerminated(char *value)

References System.Collections.Hashtable.Add(), System.Runtime.InteropServices.MemoryMarshal.CreateReadOnlySpanFromNullTerminated(), Interop.Kernel32.FreeEnvironmentStringsW(), Interop.Kernel32.GetEnvironmentStringsW(), System.ReadOnlySpan< T >.IsEmpty, System.key, System.ReadOnlySpan< T >.Slice(), and System.value.

Referenced by System.Environment.GetEnvironmentVariables().