Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 24 additions & 24 deletions src/System.Management.Automation/engine/PSVersionInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
using System.Collections;
using System.Diagnostics;
using System.Globalization;
using System.Management.Automation.Internal;
using System.Reflection;
using System.Text;
using System.Text.RegularExpressions;

Expand Down Expand Up @@ -41,7 +39,7 @@ public class PSVersionInfo
internal const string PSOSName = "OS";
internal const string SerializationVersionName = "SerializationVersion";
internal const string WSManStackVersionName = "WSManStackVersion";
private static PSVersionHashTable s_psVersionTable = null;
private static readonly PSVersionHashTable s_psVersionTable;

/// <summary>
/// A constant to track current PowerShell Version.
Expand All @@ -54,14 +52,15 @@ public class PSVersionInfo
/// For each later release of PowerShell, this constant needs to
/// be updated to reflect the right version.
/// </remarks>
private static Version s_psV1Version = new Version(1, 0);
private static Version s_psV2Version = new Version(2, 0);
private static Version s_psV3Version = new Version(3, 0);
private static Version s_psV4Version = new Version(4, 0);
private static Version s_psV5Version = new Version(5, 0);
private static Version s_psV51Version = new Version(5, 1, NTVerpVars.PRODUCTBUILD, NTVerpVars.PRODUCTBUILD_QFE);
private static SemanticVersion s_psV6Version = new SemanticVersion(6, 0, 0, null, null);
private static SemanticVersion s_psV7Version;
private static readonly Version s_psV1Version = new Version(1, 0);
private static readonly Version s_psV2Version = new Version(2, 0);
private static readonly Version s_psV3Version = new Version(3, 0);
private static readonly Version s_psV4Version = new Version(4, 0);
private static readonly Version s_psV5Version = new Version(5, 0);
private static readonly Version s_psV51Version = new Version(5, 1, NTVerpVars.PRODUCTBUILD, NTVerpVars.PRODUCTBUILD_QFE);
private static readonly SemanticVersion s_psV6Version = new SemanticVersion(6, 0, 0, preReleaseLabel: null, buildLabel: null);
private static readonly SemanticVersion s_psSemVersion;
private static readonly Version s_psVersion;

/// <summary>
/// A constant to track current PowerShell Edition.
Expand Down Expand Up @@ -100,12 +99,13 @@ static PSVersionInfo()
rawGitCommitId = mainVersion;
}

s_psV7Version = new SemanticVersion(mainVersion);
s_psSemVersion = new SemanticVersion(mainVersion);
s_psVersion = (Version)s_psSemVersion;

s_psVersionTable[PSVersionInfo.PSVersionName] = s_psV7Version;
s_psVersionTable[PSVersionInfo.PSVersionName] = s_psSemVersion;
s_psVersionTable[PSVersionInfo.PSEditionName] = PSEditionValue;
s_psVersionTable[PSGitCommitIdName] = rawGitCommitId;
s_psVersionTable[PSCompatibleVersionsName] = new Version[] { s_psV1Version, s_psV2Version, s_psV3Version, s_psV4Version, s_psV5Version, s_psV51Version, s_psV6Version, s_psV7Version };
s_psVersionTable[PSCompatibleVersionsName] = new Version[] { s_psV1Version, s_psV2Version, s_psV3Version, s_psV4Version, s_psV5Version, s_psV51Version, s_psV6Version, s_psVersion };
s_psVersionTable[PSVersionInfo.SerializationVersionName] = new Version(InternalSerializer.DefaultVersion);
s_psVersionTable[PSVersionInfo.PSRemotingProtocolVersionName] = RemotingConstants.ProtocolVersion;
s_psVersionTable[PSVersionInfo.WSManStackVersionName] = GetWSManStackVersion();
Expand All @@ -122,7 +122,7 @@ internal static Hashtable GetPSVersionTableForDownLevel()
{
var result = (Hashtable)s_psVersionTable.Clone();
// Downlevel systems don't support SemanticVersion, but Version is most likely good enough anyway.
result[PSVersionInfo.PSVersionName] = (Version)(SemanticVersion)s_psVersionTable[PSVersionInfo.PSVersionName];
result[PSVersionInfo.PSVersionName] = s_psVersion;
return result;
}

Expand Down Expand Up @@ -173,23 +173,23 @@ public static Version PSVersion
{
get
{
return (SemanticVersion)GetPSVersionTable()[PSVersionInfo.PSVersionName];
return s_psVersion;
}
}

internal static string GitCommitId
{
get
{
return (string)GetPSVersionTable()[PSGitCommitIdName];
return (string)s_psVersionTable[PSGitCommitIdName];
}
}

internal static Version[] PSCompatibleVersions
{
get
{
return (Version[])GetPSVersionTable()[PSCompatibleVersionsName];
return (Version[])s_psVersionTable[PSCompatibleVersionsName];
}
}

Expand All @@ -200,15 +200,15 @@ public static string PSEdition
{
get
{
return (string)GetPSVersionTable()[PSVersionInfo.PSEditionName];
return (string)s_psVersionTable[PSVersionInfo.PSEditionName];
}
}

internal static Version SerializationVersion
{
get
{
return (Version)GetPSVersionTable()[SerializationVersionName];
return (Version)s_psVersionTable[SerializationVersionName];
}
}

Expand Down Expand Up @@ -272,9 +272,9 @@ internal static string FeatureVersionString

internal static bool IsValidPSVersion(Version version)
{
if (version.Major == s_psV7Version.Major)
if (version.Major == s_psSemVersion.Major)
{
return version.Minor == s_psV7Version.Minor;
return version.Minor == s_psSemVersion.Minor;
}

if (version.Major == s_psV6Version.Major)
Expand Down Expand Up @@ -327,9 +327,9 @@ internal static SemanticVersion PSV6Version
get { return s_psV6Version; }
}

internal static SemanticVersion PSV7Version
internal static SemanticVersion PSCurrentVersion
{
get { return s_psV7Version; }
get { return s_psSemVersion; }
}

#endregion
Expand Down