System.Environment.GetEnvironmentVariableCore C# (CSharp) Method

GetEnvironmentVariableCore() private static method

private static GetEnvironmentVariableCore ( string variable ) : string
variable string
return string
        private static string GetEnvironmentVariableCore(string variable)
        {
            StringBuilder sb = StringBuilderCache.Acquire(128); // a somewhat reasonable default size
            int requiredSize = Interop.Kernel32.GetEnvironmentVariableW(variable, sb, sb.Capacity);
            if (requiredSize == 0 && Marshal.GetLastWin32Error() == Interop.Errors.ERROR_ENVVAR_NOT_FOUND)
            {
                StringBuilderCache.Release(sb);
                return null;
            }

            while (requiredSize > sb.Capacity)
            {
                sb.Capacity = requiredSize;
                sb.Length = 0;
                requiredSize = Interop.Kernel32.GetEnvironmentVariableW(variable, sb, sb.Capacity);
            }

            return StringBuilderCache.GetStringAndRelease(sb);
        }

Same methods

Environment::GetEnvironmentVariableCore ( string variable, EnvironmentVariableTarget target ) : string