|
1 |
| -public static class TargetFrameworkExtensions |
| 1 | +using System.Collections.Generic; |
| 2 | +using System.Linq; |
| 3 | + |
| 4 | +public static class TargetFrameworkExtensions |
2 | 5 | {
|
| 6 | + private static readonly string[] IgnoredFrameworks = { "net461", "net48", "netstandard2.0" }; |
| 7 | + |
| 8 | + private static readonly List<string> OrderedFrameworks = new() |
| 9 | + { |
| 10 | + "netcoreapp2.1", |
| 11 | + "netcoreapp3.0", |
| 12 | + "netcoreapp3.1", |
| 13 | + "net5.0", |
| 14 | + "net6.0", |
| 15 | + "net7.0", |
| 16 | + "net8.0", |
| 17 | + "net9.0", |
| 18 | + "net10.0" |
| 19 | + }; |
| 20 | + |
3 | 21 | /// <summary>
|
4 | 22 | /// Is <paramref name="instance"/> greater than <paramref name="target"/>.
|
5 | 23 | /// Only works for .NET Core TFMs
|
6 | 24 | /// </summary>
|
7 | 25 | public static bool IsGreaterThan(this TargetFramework instance, TargetFramework target)
|
8 |
| - => ((string) instance, (string) target) switch |
9 |
| - { |
10 |
| - // We ignore these, because they don't really count |
11 |
| - ("net461" or "net48" or "netstandard2.0", _) => false, |
12 |
| - (_, "net461" or "net48" or "netstandard2.0") => false, |
13 |
| - // real checks |
14 |
| - ("netcoreapp3.0" or "netcoreapp3.1" or "net5.0" or "net6.0" or "net7.0" or "net8.0" or "net9.0", "netcoreapp2.1") => true, |
15 |
| - ("netcoreapp3.1" or "net5.0" or "net6.0" or "net7.0" or "net8.0" or "net9.0", "netcoreapp3.0") => true, |
16 |
| - ("net5.0" or "net6.0" or "net7.0" or "net8.0" or "net9.0", "netcoreapp3.1") => true, |
17 |
| - ("net6.0" or "net7.0" or "net8.0" or "net9.0", "net5.0") => true, |
18 |
| - ("net7.0" or "net8.0" or "net9.0", "net6.0") => true, |
19 |
| - ("net9.0" or "net8.0", "net7.0") => true, |
20 |
| - ("net9.0", "net8.0") => true, |
21 |
| - _ => false, |
22 |
| - }; |
| 26 | + { |
| 27 | + var source = (string)instance; |
| 28 | + var compareTo = (string)target; |
| 29 | + |
| 30 | + if (IgnoredFrameworks.Contains(source) || IgnoredFrameworks.Contains(compareTo)) |
| 31 | + return false; |
| 32 | + |
| 33 | + int sourceIndex = OrderedFrameworks.IndexOf(source); |
| 34 | + int targetIndex = OrderedFrameworks.IndexOf(compareTo); |
| 35 | + |
| 36 | + return sourceIndex > targetIndex; |
| 37 | + } |
23 | 38 |
|
24 | 39 | /// <summary>
|
25 | 40 | /// Is <paramref name="instance"/> greater than <paramref name="target"/>.
|
|
0 commit comments