1
+ using System ;
1
2
using System . Collections . Generic ;
2
3
using System . Diagnostics . CodeAnalysis ;
3
4
using System . Linq ;
@@ -10,7 +11,8 @@ namespace BenchmarkDotNet.Environments
10
11
public class OsBrandStringHelper
11
12
{
12
13
// See https://en.wikipedia.org/wiki/Ver_(command)
13
- // See https://docs.microsoft.com/en-us/windows/release-information/
14
+ // See https://docs.microsoft.com/en-us/windows/release-health/release-information
15
+ // See https://docs.microsoft.com/en-us/windows/release-health/windows11-release-information
14
16
private static readonly Dictionary < string , string > WindowsBrandVersions = new Dictionary < string , string >
15
17
{
16
18
{ "1.04" , "1.0" } ,
@@ -99,22 +101,24 @@ public class OsBrandStringHelper
99
101
{ "10.0.19041" , "10 20H1 [2004, May 2020 Update]" } ,
100
102
{ "10.0.19042" , "10 20H2 [20H2, October 2020 Update]" } ,
101
103
{ "10.0.19043" , "10 21H1 [21H1, May 2021 Update]" } ,
102
- { "10.0.19044" , "10 21H2 [21H2]" }
104
+ { "10.0.19044" , "10 21H2 [21H2, November 2021 Update]" } ,
105
+ { "10.0.22000" , "11 21H2 [21H2]" } ,
103
106
} ;
104
107
105
- private class Windows10Version
108
+ private class Windows1XVersion
106
109
{
107
- private string Version { get ; }
108
- [ NotNull ] private string CodeName { get ; }
109
- [ NotNull ] private string MarketingName { get ; }
110
+ [ CanBeNull ] private string CodeVersion { get ; }
111
+ [ CanBeNull ] private string CodeName { get ; }
112
+ [ CanBeNull ] private string MarketingName { get ; }
110
113
private int BuildNumber { get ; }
111
114
112
- [ NotNull ] private string ShortifiedCodeName => CodeName . Replace ( " " , "" ) ;
113
- [ NotNull ] private string ShortifiedMarketingName => MarketingName . Replace ( " " , "" ) ;
115
+ [ NotNull ] private string MarketingNumber => BuildNumber >= 22000 ? "11" : "10" ;
116
+ [ CanBeNull ] private string ShortifiedCodeName => CodeName ? . Replace ( " " , "" ) ;
117
+ [ CanBeNull ] private string ShortifiedMarketingName => MarketingName ? . Replace ( " " , "" ) ;
114
118
115
- private Windows10Version ( string version , [ NotNull ] string codeName , [ NotNull ] string marketingName , int buildNumber )
119
+ private Windows1XVersion ( [ CanBeNull ] string codeVersion , [ CanBeNull ] string codeName , [ CanBeNull ] string marketingName , int buildNumber )
116
120
{
117
- Version = version ;
121
+ CodeVersion = codeVersion ;
118
122
CodeName = codeName ;
119
123
MarketingName = marketingName ;
120
124
BuildNumber = buildNumber ;
@@ -129,31 +133,46 @@ private string ToFullVersion([CanBeNull] int? ubr = null)
129
133
// When people past in on GitHub, it can be a reason of an ugly horizontal scrollbar.
130
134
// To avoid this, we are trying to minimize this line and use the minimum possible number of characters.
131
135
public string ToPrettifiedString ( [ CanBeNull ] int ? ubr )
132
- => Version == ShortifiedCodeName
133
- ? $ "{ ToFullVersion ( ubr ) } ({ Collapse ( Version , ShortifiedMarketingName ) } )"
134
- : $ "{ ToFullVersion ( ubr ) } ({ Collapse ( Version , ShortifiedMarketingName , ShortifiedCodeName ) } )";
136
+ => CodeVersion == ShortifiedCodeName
137
+ ? $ "{ MarketingNumber } ({ Collapse ( ToFullVersion ( ubr ) , CodeVersion , ShortifiedMarketingName ) } )"
138
+ : $ "{ MarketingNumber } ({ Collapse ( ToFullVersion ( ubr ) , CodeVersion , ShortifiedMarketingName , ShortifiedCodeName ) } )";
135
139
136
140
// See https://en.wikipedia.org/wiki/Windows_10_version_history
137
- private static readonly List < Windows10Version > WellKnownVersions = new List < Windows10Version >
141
+ // See https://en.wikipedia.org/wiki/Windows_11_version_history
142
+ private static readonly List < Windows1XVersion > WellKnownVersions = new ( )
138
143
{
139
- new Windows10Version ( "1507" , "Threshold 1" , "RTM" , 10240 ) ,
140
- new Windows10Version ( "1511" , "Threshold 2" , "November Update" , 10586 ) ,
141
- new Windows10Version ( "1607" , "Redstone 1" , "Anniversary Update" , 14393 ) ,
142
- new Windows10Version ( "1703" , "Redstone 2" , "Creators Update" , 15063 ) ,
143
- new Windows10Version ( "1709" , "Redstone 3" , "Fall Creators Update" , 16299 ) ,
144
- new Windows10Version ( "1803" , "Redstone 4" , "April 2018 Update" , 17134 ) ,
145
- new Windows10Version ( "1809" , "Redstone 5" , "October 2018 Update" , 17763 ) ,
146
- new Windows10Version ( "1903" , "19H1" , "May 2019 Update" , 18362 ) ,
147
- new Windows10Version ( "1909" , "19H2" , "November 2019 Update" , 18363 ) ,
148
- new Windows10Version ( "2004" , "20H1" , "May 2020 Update" , 19041 ) ,
149
- new Windows10Version ( "20H2" , "20H2" , "October 2020 Update" , 19042 ) ,
150
- new Windows10Version ( "21H1" , "21H1" , "May 2021 Update" , 19043 ) ,
151
- new Windows10Version ( "21H2" , "21H2" , "" , 19044 ) , // The markingName is not announced yet
144
+ // Windows 10
145
+ new Windows1XVersion ( "1507" , "Threshold 1" , "RTM" , 10240 ) ,
146
+ new Windows1XVersion ( "1511" , "Threshold 2" , "November Update" , 10586 ) ,
147
+ new Windows1XVersion ( "1607" , "Redstone 1" , "Anniversary Update" , 14393 ) ,
148
+ new Windows1XVersion ( "1703" , "Redstone 2" , "Creators Update" , 15063 ) ,
149
+ new Windows1XVersion ( "1709" , "Redstone 3" , "Fall Creators Update" , 16299 ) ,
150
+ new Windows1XVersion ( "1803" , "Redstone 4" , "April 2018 Update" , 17134 ) ,
151
+ new Windows1XVersion ( "1809" , "Redstone 5" , "October 2018 Update" , 17763 ) ,
152
+ new Windows1XVersion ( "1903" , "19H1" , "May 2019 Update" , 18362 ) ,
153
+ new Windows1XVersion ( "1909" , "19H2" , "November 2019 Update" , 18363 ) ,
154
+ new Windows1XVersion ( "2004" , "20H1" , "May 2020 Update" , 19041 ) ,
155
+ new Windows1XVersion ( "20H2" , "20H2" , "October 2020 Update" , 19042 ) ,
156
+ new Windows1XVersion ( "21H1" , "21H1" , "May 2021 Update" , 19043 ) ,
157
+ new Windows1XVersion ( "21H2" , "21H2" , "November 2021 Update" , 19044 ) ,
158
+ new Windows1XVersion ( "21H2" , "21H2" , "November 2021 Update" , 19044 ) ,
159
+ // Windows 11
160
+ new Windows1XVersion ( "21H2" , "21H2" , null , 22000 ) ,
152
161
} ;
153
162
154
163
[ CanBeNull ]
155
- public static Windows10Version Resolve ( [ NotNull ] string osVersion )
156
- => WellKnownVersions . FirstOrDefault ( v => osVersion == $ "10.0.{ v . BuildNumber } ") ;
164
+ public static Windows1XVersion Resolve ( [ NotNull ] string osVersionString )
165
+ {
166
+ var windows1XVersion = WellKnownVersions . FirstOrDefault ( v => osVersionString == $ "10.0.{ v . BuildNumber } ") ;
167
+ if ( windows1XVersion != null )
168
+ return windows1XVersion ;
169
+ if ( Version . TryParse ( osVersionString , out var osVersion ) )
170
+ {
171
+ if ( osVersion . Major == 10 && osVersion . Minor == 0 )
172
+ return new Windows1XVersion ( null , null , null , osVersion . Build ) ;
173
+ }
174
+ return null ;
175
+ }
157
176
}
158
177
159
178
/// <summary>
@@ -174,9 +193,9 @@ public static string Prettify([NotNull] string osName, [NotNull] string osVersio
174
193
[ NotNull ]
175
194
private static string PrettifyWindows ( [ NotNull ] string osVersion , [ CanBeNull ] int ? windowsUbr )
176
195
{
177
- var windows10Version = Windows10Version . Resolve ( osVersion ) ;
178
- if ( windows10Version != null )
179
- return "Windows " + windows10Version . ToPrettifiedString ( windowsUbr ) ;
196
+ var windows1XVersion = Windows1XVersion . Resolve ( osVersion ) ;
197
+ if ( windows1XVersion != null )
198
+ return "Windows " + windows1XVersion . ToPrettifiedString ( windowsUbr ) ;
180
199
181
200
string brandVersion = WindowsBrandVersions . GetValueOrDefault ( osVersion ) ;
182
201
string completeOsVersion = windowsUbr != null && osVersion . Count ( c => c == '.' ) == 2
0 commit comments