@@ -19,6 +19,13 @@ internal class PSVersionInfo
19
19
internal const string PSVersionTableName = "PSVersionTable" ;
20
20
internal const string PSRemotingProtocolVersionName = "PSRemotingProtocolVersion" ;
21
21
internal const string PSVersionName = "PSVersion" ;
22
+ internal const string PSEditionName = "PSEdition" ;
23
+ internal const string PSBuildVersionName = "BuildVersion" ;
24
+ internal const string PSGitCommitIdName = "GitCommitId" ;
25
+ internal const string PSCompatibleVersionsName = "PSCompatibleVersions" ;
26
+ internal const string PSCLRVersionName = "CLRVersion" ;
27
+ internal const string PSPlatformName = "Platform" ;
28
+ internal const string PSOSName = "OS" ;
22
29
internal const string SerializationVersionName = "SerializationVersion" ;
23
30
internal const string WSManStackVersionName = "WSManStackVersion" ;
24
31
private static PSVersionHashTable s_psVersionTable = null ;
@@ -57,20 +64,20 @@ static PSVersionInfo()
57
64
s_psVersionTable = new PSVersionHashTable ( StringComparer . OrdinalIgnoreCase ) ;
58
65
59
66
s_psVersionTable [ PSVersionInfo . PSVersionName ] = s_psV6Version ;
60
- s_psVersionTable [ "PSEdition" ] = PSEditionValue ;
61
- s_psVersionTable [ "BuildVersion" ] = GetBuildVersion ( ) ;
62
- s_psVersionTable [ "GitCommitId" ] = GetCommitInfo ( ) ;
63
- s_psVersionTable [ "PSCompatibleVersions" ] = new Version [ ] { s_psV1Version , s_psV2Version , s_psV3Version , s_psV4Version , s_psV5Version , s_psV51Version , s_psV6Version } ;
67
+ s_psVersionTable [ PSVersionInfo . PSEditionName ] = PSEditionValue ;
68
+ s_psVersionTable [ PSBuildVersionName ] = GetBuildVersion ( ) ;
69
+ s_psVersionTable [ PSGitCommitIdName ] = GetCommitInfo ( ) ;
70
+ s_psVersionTable [ PSCompatibleVersionsName ] = new Version [ ] { s_psV1Version , s_psV2Version , s_psV3Version , s_psV4Version , s_psV5Version , s_psV51Version , s_psV6Version } ;
64
71
s_psVersionTable [ PSVersionInfo . SerializationVersionName ] = new Version ( InternalSerializer . DefaultVersion ) ;
65
72
s_psVersionTable [ PSVersionInfo . PSRemotingProtocolVersionName ] = RemotingConstants . ProtocolVersion ;
66
73
s_psVersionTable [ PSVersionInfo . WSManStackVersionName ] = GetWSManStackVersion ( ) ;
67
- s_psVersionTable [ "Platform" ] = Environment . OSVersion . Platform . ToString ( ) ;
74
+ s_psVersionTable [ PSPlatformName ] = Environment . OSVersion . Platform . ToString ( ) ;
68
75
#if CORECLR
69
-
57AE
span>s_psVersionTable [ "OS" ] = Runtime . InteropServices . RuntimeInformation . OSDescription . ToString ( ) ;
70
- s_psVersionTable [ "CLRVersion" ] = null ;
76
+ s_psVersionTable [ PSCLRVersionName ] = null ;
77
+ s_psVersionTable [ PSOSName ] = Runtime . InteropServices . RuntimeInformation . OSDescription . ToString ( ) ;
71
78
#else
72
- s_psVersionTable [ "CLRVersion" ] = Environment . Version ;
73
- s_psVersionTable [ "OS" ] = Environment . OSVersion . ToString ( ) ;
79
+ s_psVersionTable [ PSCLRVersionName ] = Environment . Version ;
80
+ s_psVersionTable [ PSOSName ] = Environment . OSVersion . ToString ( ) ;
74
81
#endif
75
82
}
76
83
@@ -160,47 +167,47 @@ internal static string GitCommitId
160
167
{
161
168
get
162
169
{
163
- return ( string ) GetPSVersionTable ( ) [ "GitCommitId" ] ;
170
+ return ( string ) GetPSVersionTable ( ) [ PSGitCommitIdName ] ;
164
171
}
165
172
}
166
173
167
174
internal static Version CLRVersion
168
175
{
169
176
get
170
177
{
171
- return ( Version ) GetPSVersionTable ( ) [ "CLRVersion" ] ;
178
+ return ( Version ) GetPSVersionTable ( ) [ PSCLRVersionName ] ;
172
179
}
173
180
}
174
181
175
182
internal static Version BuildVersion
176
183
{
177
184
get
178
185
{
179
- return ( Version ) GetPSVersionTable ( ) [ "BuildVersion" ] ;
186
+ return ( Version ) GetPSVersionTable ( ) [ PSBuildVersionName ] ;
180
187
}
181
188
}
182
189
183
190
internal static Version [ ] PSCompatibleVersions
184
191
{
185
192
get
186
193
{
187
- return ( Version [ ] ) GetPSVersionTable ( ) [ "PSCompatibleVersions" ] ;
194
+ return ( Version [ ] ) GetPSVersionTable ( ) [ PSCompatibleVersionsName ] ;
188
195
}
189
196
}
190
197
191
198
internal static string PSEdition
192
199
{
193
200
get
194
201
{
195
- return ( string ) GetPSVersionTable ( ) [ "PSEdition" ] ;
202
+ return ( string ) GetPSVersionTable ( ) [ PSVersionInfo . PSEditionName ] ;
196
203
}
197
204
}
198
205
199
206
internal static Version SerializationVersion
200
207
{
201
208
get
202
209
{
203
- return ( Version ) GetPSVersionTable ( ) [ "SerializationVersion" ] ;
210
+ return ( Version ) GetPSVersionTable ( ) [ SerializationVersionName ] ;
204
211
}
205
212
}
206
213
@@ -324,21 +331,54 @@ internal static SemanticVersion PSV6Version
324
331
/// </summary>
325
332
public sealed class PSVersionHashTable : Hashtable , IEnumerable
326
333
{
334
+ private static readonly PSVersionTableComparer s_keysComparer = new PSVersionTableComparer ( ) ;
327
335
internal PSVersionHashTable ( IEqualityComparer equalityComparer ) : base ( equalityComparer )
328
336
{
329
337
}
330
338
331
339
/// <summary>
332
340
/// Returns ordered collection with Keys of 'PSVersionHashTable'
341
+ /// We want see special order:
342
+ /// 1. PSVersionName
343
+ /// 2. PSEditionName
344
+ /// 3. Remaining properties in alphabetical order
333
345
/// </summary>
334
346
public override ICollection Keys
335
347
{
336
348
get
337
349
{
338
- Array arr = new string [ base . Keys . Count ] ;
339
- base . Keys . CopyTo ( arr , 0 ) ;
340
- Array . Sort ( arr , StringComparer . OrdinalIgnoreCase ) ;
341
- return arr ;
350
+ ArrayList keyList = new ArrayList ( base . Keys ) ;
351
+ keyList . Sort ( s_keysComparer ) ;
352
+ return keyList ;
353
+ }
354
+ }
355
+
356
+ private class PSVersionTableComparer : IComparer
357
+ {
358
+ public int Compare ( object x , object y )
359
+ {
360
+ string xString = ( string ) LanguagePrimitives . ConvertTo ( x , typeof ( string ) , CultureInfo . CurrentCulture ) ;
361
+ string yString = ( string ) LanguagePrimitives . ConvertTo ( y , typeof ( string ) , CultureInfo . CurrentCulture ) ;
362
+ if ( PSVersionInfo . PSVersionName . Equals ( xString , StringComparison . OrdinalIgnoreCase ) )
363
+ {
364
+ return - 1 ;
365
+ }
366
+ else if ( PSVersionInfo . PSVersionName . Equals ( yString , StringComparison . OrdinalIgnoreCase ) )
367
+ {
368
+ return 1 ;
369
+ }
370
+ else if ( PSVersionInfo . PSEditionName . Equals ( xString , StringComparison . OrdinalIgnoreCase ) )
371
+ {
372
+ return - 1 ;
373
+ }
374
+ else if ( PSVersionInfo . PSEditionName . Equals ( yString , StringComparison . OrdinalIgnoreCase ) )
375
+ {
376
+ return 1 ;
377
+ }
378
+ else
379
+ {
380
+ return String . Compare ( xString , yString , StringComparison . OrdinalIgnoreCase ) ;
381
+ }
342
382
}
343
383
}
344
384
@@ -348,9 +388,9 @@ public override ICollection Keys
348
388
/// </summary>
349
389
IEnumerator IEnumerable . GetEnumerator ( )
350
390
{
351
- foreach ( string key in Keys )
391
+ foreach ( object key in Keys )
352
392
{
353
- yield return new System . Collections . DictionaryEntry ( key , this [ key ] ) ;
393
+ yield return new DictionaryEntry ( key , this [ key ] ) ;
354
394
}
355
395
}
356
396
}
0 commit comments