Skip to content

Commit 3551e8a

Browse files
authored
Add polyfills for Version.Parse(...) and Version.TryParse(...) (#27)
1 parent 34464d9 commit 3551e8a

1 file changed

Lines changed: 39 additions & 0 deletions

File tree

PolyShim/NetCore10/Version.cs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// The following comment is required to instruct analyzers to skip this file
2+
// <auto-generated/>
3+
4+
#if (NETFRAMEWORK && !NET40_OR_GREATER)
5+
#nullable enable
6+
// ReSharper disable RedundantUsingDirective
7+
// ReSharper disable CheckNamespace
8+
// ReSharper disable InconsistentNaming
9+
// ReSharper disable PartialTypeWithSinglePart
10+
11+
using System;
12+
13+
internal static partial class PolyfillExtensions
14+
{
15+
extension(Version)
16+
{
17+
// https://learn.microsoft.com/dotnet/api/system.version.parse
18+
public static Version Parse(string input) => new(input);
19+
20+
// https://learn.microsoft.com/dotnet/api/system.version.tryparse
21+
public static bool TryParse(string? input, out Version? result)
22+
{
23+
result = null;
24+
if (input is null)
25+
return false;
26+
27+
try
28+
{
29+
result = new Version(input);
30+
return true;
31+
}
32+
catch
33+
{
34+
return false;
35+
}
36+
}
37+
}
38+
}
39+
#endif

0 commit comments

Comments
 (0)