X Tutup
Skip to content
Closed
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,33 @@

namespace System.Management.Automation
{
/// <summary>
/// To make it easier to specify a version, we add some conversions that wouldn't happen otherwise:
/// * A simple integer, i.e. 2;
/// * A string without a dot, i.e. "2".
/// * the string "off" sets the version to 0.0 (unset).
/// * the string "latest" sets to the current version.
/// </summary>
internal sealed class ArgumentToPSVersionTransformationAttribute : ArgumentToVersionTransformationAttribute
{
protected override bool TryConvertFromString(string versionString, [NotNullWhen(true)] out Version? version)
{
if (string.Equals("off", versionString, StringComparison.OrdinalIgnoreCase))
{
version = new Version(0, 0);
return true;
}

if (string.Equals("latest", versionString, StringComparison.OrdinalIgnoreCase))
{
version = PSVersionInfo.PSVersion;
return true;
}

return base.TryConvertFromString(versionString, out version);
}
}

/// <summary>
/// To make it easier to specify a version, we add some conversions that wouldn't happen otherwise:
/// * A simple integer, i.e. 2;
Expand Down
17 changes: 0 additions & 17 deletions src/System.Management.Automation/engine/InternalCommands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2635,23 +2635,6 @@ public SwitchParameter Off

private SwitchParameter _off;

/// <summary>
/// Handle 'latest', which we interpret to be the current version of PowerShell.
/// </summary>
private sealed class ArgumentToPSVersionTransformationAttribute : ArgumentToVersionTransformationAttribute
{
protected override bool TryConvertFromString(string versionString, [NotNullWhen(true)] out Version version)
{
if (string.Equals("latest", versionString, StringComparison.OrdinalIgnoreCase))
{
version = PSVersionInfo.PSVersion;
return true;
}

return base.TryConvertFromString(versionString, out version);
}
}

private sealed class ValidateVersionAttribute : ValidateArgumentsAttribute
{
protected override void Validate(object arguments, EngineIntrinsics engineIntrinsics)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -263,26 +263,6 @@ public override SwitchParameter UseSSL
}
}

private sealed class ArgumentToPSVersionTransformationAttribute : ArgumentToVersionTransformationAttribute
{
protected override bool TryConvertFromString(string versionString, [NotNullWhen(true)] out Version version)
{
if (string.Equals("off", versionString, StringComparison.OrdinalIgnoreCase))
{
version = new Version(0, 0);
return true;
}

if (string.Equals("latest", versionString, StringComparison.OrdinalIgnoreCase))
{
version = PSVersionInfo.PSVersion;
return true;
}

return base.TryConvertFromString(versionString, out version);
}
}

private static readonly Version s_OffVersion = new Version(0, 0);

private sealed class ValidateVersionAttribute : ValidateArgumentsAttribute
Expand Down
2 changes: 2 additions & 0 deletions tools/packaging/packaging.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -2294,6 +2294,8 @@ function CleanupGeneratedSourceCode
'[Microsoft.PowerShell.Commands.SetStrictModeCommand.ArgumentToPSVersionTransformationAttribute]'
'[Microsoft.PowerShell.Commands.HttpVersionCompletionsAttribute]'
'[System.Management.Automation.ArgumentToVersionTransformationAttribute]'
'[Microsoft.PowerShell.Commands.InvokeCommandCommand.ValidateVersionAttribute]'
'[System.Management.Automation.ArgumentToPSVersionTransformationAttribute]'
)

$patternsToReplace = @(
Expand Down
X Tutup