Skip to content

Commit b632723

Browse files
authored
Add environment.process path (#485)
1 parent 8e20f13 commit b632723

File tree

20 files changed

+355
-3
lines changed

20 files changed

+355
-3
lines changed

api_list.include.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,7 @@
235235
#### Environment
236236

237237
* `ProcessId` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.environment.processid?view=net-11.0#system-environment-processid)
238+
* `ProcessPath` [reference](https://learn.microsoft.com/en-us/dotnet/api/system.environment.processpath?view=net-11.0#system-environment-processpath)
238239

239240

240241
#### EventInfo

src/Consume/Consume.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -551,6 +551,11 @@ void Enum_Methods()
551551
values = Enum.GetValuesAsUnderlyingType<DayOfWeek>();
552552
}
553553

554+
void Environment_Methods()
555+
{
556+
var processPath = Environment.ProcessPath;
557+
}
558+
554559
void EnumerationOptions_Methods()
555560
{
556561
var options = new EnumerationOptions

src/Polyfill/EnvironmentPolyfill.cs

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
1-
#if !NET5_0_OR_GREATER
2-
31
namespace Polyfills;
42

53
using System;
64
using System.Diagnostics;
75

86
static partial class Polyfill
97
{
8+
#if !NET5_0_OR_GREATER
109
static int processId;
1110

1211
extension(Environment)
@@ -29,5 +28,30 @@ public static int ProcessId
2928
}
3029
}
3130
}
32-
}
3331
#endif
32+
33+
#if !NET6_0_OR_GREATER
34+
static string? processPath;
35+
36+
extension(Environment)
37+
{
38+
/// <summary>
39+
/// Gets the path of the executable that started the currently executing process.
40+
/// </summary>
41+
//Link: https://learn.microsoft.com/en-us/dotnet/api/system.environment.processpath?view=net-11.0#system-environment-processpath
42+
public static string? ProcessPath
43+
{
44+
get
45+
{
46+
if (processPath is null)
47+
{
48+
using var process = Process.GetCurrentProcess();
49+
processPath = process.MainModule?.FileName;
50+
}
51+
52+
return processPath;
53+
}
54+
}
55+
}
56+
#endif
57+
}

src/Split/net461/EnvironmentPolyfill.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,23 @@ public static int ProcessId
2424
}
2525
}
2626
}
27+
static string? processPath;
28+
extension(Environment)
29+
{
30+
/// <summary>
31+
/// Gets the path of the executable that started the currently executing process.
32+
/// </summary>
33+
public static string? ProcessPath
34+
{
35+
get
36+
{
37+
if (processPath is null)
38+
{
39+
using var process = Process.GetCurrentProcess();
40+
processPath = process.MainModule?.FileName;
41+
}
42+
return processPath;
43+
}
44+
}
45+
}
2746
}

src/Split/net462/EnvironmentPolyfill.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,23 @@ public static int ProcessId
2424
}
2525
}
2626
}
27+
static string? processPath;
28+
extension(Environment)
29+
{
30+
/// <summary>
31+
/// Gets the path of the executable that started the currently executing process.
32+
/// </summary>
33+
public static string? ProcessPath
34+
{
35+
get
36+
{
37+
if (processPath is null)
38+
{
39+
using var process = Process.GetCurrentProcess();
40+
processPath = process.MainModule?.FileName;
41+
}
42+
return processPath;
43+
}
44+
}
45+
}
2746
}

src/Split/net47/EnvironmentPolyfill.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,23 @@ public static int ProcessId
2424
}
2525
}
2626
}
27+
static string? processPath;
28+
extension(Environment)
29+
{
30+
/// <summary>
31+
/// Gets the path of the executable that started the currently executing process.
32+
/// </summary>
33+
public static string? ProcessPath
34+
{
35+
get
36+
{
37+
if (processPath is null)
38+
{
39+
using var process = Process.GetCurrentProcess();
40+
processPath = process.MainModule?.FileName;
41+
}
42+
return processPath;
43+
}
44+
}
45+
}
2746
}

src/Split/net471/EnvironmentPolyfill.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,23 @@ public static int ProcessId
2424
}
2525
}
2626
}
27+
static string? processPath;
28+
extension(Environment)
29+
{
30+
/// <summary>
31+
/// Gets the path of the executable that started the currently executing process.
32+
/// </summary>
33+
public static string? ProcessPath
34+
{
35+
get
36+
{
37+
if (processPath is null)
38+
{
39+
using var process = Process.GetCurrentProcess();
40+
processPath = process.MainModule?.FileName;
41+
}
42+
return processPath;
43+
}
44+
}
45+
}
2746
}

src/Split/net472/EnvironmentPolyfill.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,23 @@ public static int ProcessId
2424
}
2525
}
2626
}
27+
static string? processPath;
28+
extension(Environment)
29+
{
30+
/// <summary>
31+
/// Gets the path of the executable that started the currently executing process.
32+
/// </summary>
33+
public static string? ProcessPath
34+
{
35+
get
36+
{
37+
if (processPath is null)
38+
{
39+
using var process = Process.GetCurrentProcess();
40+
processPath = process.MainModule?.FileName;
41+
}
42+
return processPath;
43+
}
44+
}
45+
}
2746
}

src/Split/net48/EnvironmentPolyfill.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,23 @@ public static int ProcessId
2424
}
2525
}
2626
}
27+
static string? processPath;
28+
extension(Environment)
29+
{
30+
/// <summary>
31+
/// Gets the path of the executable that started the currently executing process.
32+
/// </summary>
33+
public static string? ProcessPath
34+
{
35+
get
36+
{
37+
if (processPath is null)
38+
{
39+
using var process = Process.GetCurrentProcess();
40+
processPath = process.MainModule?.FileName;
41+
}
42+
return processPath;
43+
}
44+
}
45+
}
2746
}

src/Split/net481/EnvironmentPolyfill.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,23 @@ public static int ProcessId
2424
}
2525
}
2626
}
27+
static string? processPath;
28+
extension(Environment)
29+
{
30+
/// <summary>
31+
/// Gets the path of the executable that started the currently executing process.
32+
/// </summary>
33+
public static string? ProcessPath
34+
{
35+
get
36+
{
37+
if (processPath is null)
38+
{
39+
using var process = Process.GetCurrentProcess();
40+
processPath = process.MainModule?.FileName;
41+
}
42+
return processPath;
43+
}
44+
}
45+
}
2746
}

0 commit comments

Comments
 (0)