-
Notifications
You must be signed in to change notification settings - Fork 293
Expand file tree
/
Copy pathSystemEnvironment.cs
More file actions
64 lines (46 loc) · 2.23 KB
/
SystemEnvironment.cs
File metadata and controls
64 lines (46 loc) · 2.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
namespace Microsoft.Testing.Platform.Helpers;
[SuppressMessage("ApiDesign", "RS0030:Do not use banned APIs", Justification = "This is the wrapper for Environment type.")]
internal sealed class SystemEnvironment : IEnvironment
{
public string CommandLine => Environment.CommandLine;
public string MachineName => Environment.MachineName;
public string NewLine => Environment.NewLine;
#if !NETCOREAPP
public int ProcessId
{
get
{
int processId = field;
if (processId == 0)
{
field = processId = GetProcessId();
// Assume that process Id zero is invalid for user processes. It holds for all mainstream operating systems.
Debug.Assert(processId != 0, "processId is expected to be non-zero.");
}
return processId;
static int GetProcessId()
{
using var process = Process.GetCurrentProcess();
return process.Id;
}
}
}
#else
public int ProcessId => Environment.ProcessId;
#endif
public string OsVersion => Environment.OSVersion.ToString();
#if NETCOREAPP
public string? ProcessPath => Environment.ProcessPath;
#endif
public Version Version => Environment.Version;
public string[] GetCommandLineArgs() => Environment.GetCommandLineArgs();
public string? GetEnvironmentVariable(string name) => Environment.GetEnvironmentVariable(name);
public IDictionary GetEnvironmentVariables() => Environment.GetEnvironmentVariables();
public string GetFolderPath(Environment.SpecialFolder folder, Environment.SpecialFolderOption option) => Environment.GetFolderPath(folder, option);
public void FailFast(string? message, Exception? exception) => Environment.FailFast(message, exception);
public void FailFast(string? message) => Environment.FailFast(message);
public void SetEnvironmentVariable(string variable, string? value) => Environment.SetEnvironmentVariable(variable, value);
public void Exit(int exitCode) => Environment.Exit(exitCode);
}