diff --git a/PolyShim.Tests/Net50/EnvironmentTests.cs b/PolyShim.Tests/Net50/EnvironmentTests.cs new file mode 100644 index 0000000..b8a659e --- /dev/null +++ b/PolyShim.Tests/Net50/EnvironmentTests.cs @@ -0,0 +1,19 @@ +using System; +using System.Diagnostics; +using FluentAssertions; +using Xunit; + +namespace PolyShim.Tests.Net50; + +public class EnvironmentTests +{ + [Fact] + public void ProcessId_Test() + { + // Arrange + using var process = Process.GetCurrentProcess(); + + // Act & assert + Environment.ProcessId.Should().Be(process.Id); + } +} diff --git a/PolyShim.Tests/Net60/EnvironmentTests.cs b/PolyShim.Tests/Net60/EnvironmentTests.cs new file mode 100644 index 0000000..46bd194 --- /dev/null +++ b/PolyShim.Tests/Net60/EnvironmentTests.cs @@ -0,0 +1,19 @@ +using System; +using System.Diagnostics; +using FluentAssertions; +using Xunit; + +namespace PolyShim.Tests.Net60; + +public class EnvironmentTests +{ + [Fact] + public void ProcessPath_Test() + { + // Arrange + using var process = Process.GetCurrentProcess(); + + // Act & assert + Environment.ProcessPath.Should().Be(process.MainModule?.FileName); + } +} diff --git a/PolyShim/Net50/Environment.cs b/PolyShim/Net50/Environment.cs new file mode 100644 index 0000000..9942d5d --- /dev/null +++ b/PolyShim/Net50/Environment.cs @@ -0,0 +1,32 @@ +// The following comment is required to instruct analyzers to skip this file +// + +#if (NETCOREAPP && !NET5_0_OR_GREATER) || (NETFRAMEWORK) || (NETSTANDARD) +#nullable enable +// ReSharper disable RedundantUsingDirective +// ReSharper disable CheckNamespace +// ReSharper disable InconsistentNaming +// ReSharper disable PartialTypeWithSinglePart + +using System; +using System.Diagnostics; + +internal static partial class PolyfillExtensions +{ + extension(Environment) + { +// No Process class in .NET Standard 1.x +#if !NETSTANDARD || NETSTANDARD2_0_OR_GREATER + // https://learn.microsoft.com/dotnet/api/system.environment.processid + public static int ProcessId + { + get + { + using var process = Process.GetCurrentProcess(); + return process.Id; + } + } +#endif + } +} +#endif \ No newline at end of file