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 @@ -12,7 +12,7 @@ namespace System.Management.Automation
/// <summary>
/// This is used for automatic conversions to be performed in shell variables.
/// </summary>
internal sealed class ArgumentTypeConverterAttribute : ArgumentTransformationAttribute
public sealed class ArgumentTypeConverterAttribute : ArgumentTransformationAttribute
{
/// <summary>
/// This ctor form is used to initialize shell variables
Expand All @@ -36,6 +36,12 @@ internal Type TargetType
}
}

/// <summary>
/// Transforms the inputData.
/// </summary>
/// <param name="engineIntrinsics">Object of type EngineIntrinsics.</param>
/// <param name="inputData">Object to be transformed.</param>
/// <returns>The object after transformation.</returns>
public override object Transform(EngineIntrinsics engineIntrinsics, object inputData)
{
return Transform(engineIntrinsics, inputData, false, false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -230,8 +230,20 @@ public string PipelineVariable

private MshCommandRuntime _commandRuntime;

internal class ValidateVariableName : ValidateArgumentsAttribute
/// <summary>
/// Validates variable name to be valid.
/// </summary>
public class ValidateVariableName : ValidateArgumentsAttribute
{
/// <summary>
/// Validate the value of arguments is a valid variable name.
/// </summary>
/// <param name="arguments">
/// The value of the arguments is a variable name to be validated.
/// </param>
/// <param name="engineIntrinsics">
/// Instance of EngineIntrinsics class.
/// </param>
protected override void Validate(object arguments, EngineIntrinsics engineIntrinsics)
{
string varName = arguments as string;
Expand Down
20 changes: 17 additions & 3 deletions src/System.Management.Automation/engine/InternalCommands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2005,8 +2005,14 @@ public SwitchParameter Off
/// * A string without a dot, i.e. "2"
/// * The string 'latest', which we interpret to be the current version of PowerShell.
/// </summary>
private sealed class ArgumentToVersionTransformationAttribute : ArgumentTransformationAttribute
{
public sealed class ArgumentToVersionTransformationAttribute : ArgumentTransformationAttribute
{
/// <summary>
/// Transform the argument to a version.
/// </summary>
/// <param name="engineIntrinsics">EngineIntrinsics object.</param>
/// <param name="inputData">Value of attribute to be transformmed.</param>
/// <returns>The object after transformation.</returns>
public override object Transform(EngineIntrinsics engineIntrinsics, object inputData)
{
object version = PSObject.Base(inputData);
Expand Down Expand Up @@ -2043,8 +2049,16 @@ public override object Transform(EngineIntrinsics engineIntrinsics, object input
}
}

private sealed class ValidateVersionAttribute : ValidateArgumentsAttribute
/// <summary>
/// Attribute to validate the version.
/// </summary>
public sealed class ValidateVersionAttribute : ValidateArgumentsAttribute
{
/// <summary>
/// Validate the arguments is a valid version.
/// </summary>
/// <param name="arguments">Value of the version argument.</param>
/// <param name="engineIntrinsics">EngineIntrinsics object.</param>
protected override void Validate(object arguments, EngineIntrinsics engineIntrinsics)
{
Version version = arguments as Version;
Expand Down
55 changes: 53 additions & 2 deletions src/System.Management.Automation/engine/LanguagePrimitives.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1888,15 +1888,29 @@ public static bool TryConvertTo(object valueToConvert, Type resultType, IFormatP

#endregion public type conversion

internal class EnumMultipleTypeConverter : EnumSingleTypeConverter
/// <summary>
/// Convert multiple Enum types.
/// </summary>
public class EnumMultipleTypeConverter : EnumSingleTypeConverter
{
/// <summary>
/// Convert from sourceValue to the specified type.
/// </summary>
/// <param name="sourceValue">Value to be converted.</param>
/// <param name="destinationType">Type to which sourceValue should be converted to.</param>
/// <param name="formatProvider">Format provider for the conversion.</param>
/// <param name="ignoreCase">Whether to ignore the case.</param>
/// <returns>The object after conversion.</returns>
public override object ConvertFrom(object sourceValue, Type destinationType, IFormatProvider formatProvider, bool ignoreCase)
{
return EnumSingleTypeConverter.BaseConvertFrom(sourceValue, destinationType, formatProvider, ignoreCase, true);
}
}

internal class EnumSingleTypeConverter : PSTypeConverter
/// <summary>
/// Convert single Enum type.
/// </summary>
public class EnumSingleTypeConverter : PSTypeConverter
{
private class EnumHashEntry
{
Expand Down Expand Up @@ -1976,6 +1990,12 @@ private static EnumHashEntry GetEnumHashEntry(Type enumType)
}
}

/// <summary>
/// Verify if conversion from sourceValue can be done to type destinationType.
/// </summary>
/// <param name="sourceValue">Value to be converted.</param>
/// <param name="destinationType">Type to which sourceValue should be converted to.</param>
/// <returns>Whether the sourceValue can be converted to destinationType.</returns>
public override bool CanConvertFrom(object sourceValue, Type destinationType)
{
return sourceValue is string && destinationType.IsEnum;
Expand Down Expand Up @@ -2091,11 +2111,28 @@ internal static string EnumValues(Type enumType)
return string.Join(CultureInfo.CurrentUICulture.TextInfo.ListSeparator, enumHashEntry.names);
}

/// <summary>
/// Convert from sourceValue to the specified type.
/// </summary>
/// <param name="sourceValue">Value to be converted.</param>
/// <param name="destinationType">Type to which sourceValue should be converted to.</param>
/// <param name="formatProvider">Format provider for the conversion.</param>
/// <param name="ignoreCase">Whether to ignore the case.</param>
/// <returns>The converted object.</returns>
public override object ConvertFrom(object sourceValue, Type destinationType, IFormatProvider formatProvider, bool ignoreCase)
{
return EnumSingleTypeConverter.BaseConvertFrom(sourceValue, destinationType, formatProvider, ignoreCase, false);
}

/// <summary>
/// Convert from sourceValue to the specified type.
/// </summary>
/// <param name="sourceValue">Value to be converted.</param>
/// <param name="destinationType">Type to which sourceValue should be converted to.</param>
/// <param name="formatProvider">Format provider for the conversion.</param>
/// <param name="ignoreCase">Whether to ignore the case.</param>
/// <param name="multipleValues">Whether to convert multiple values.</param>
/// <returns>The converted object.</returns>
protected static object BaseConvertFrom(object sourceValue, Type destinationType, IFormatProvider formatProvider, bool ignoreCase, bool multipleValues)
{
Diagnostics.Assert(sourceValue != null, "the type converter has a special case for null source values");
Expand Down Expand Up @@ -2235,11 +2272,25 @@ protected static object BaseConvertFrom(object sourceValue, Type destinationType
return Enum.ToObject(destinationType, returnUInt64);
}

/// <summary>
/// Verify if conversion from sourceValue to destinationType can be done. This is always false.
/// </summary>
/// <param name="sourceValue">Value to be converted.</param>
/// <param name="destinationType">Type to which sourceValue should be converted to.</param>
/// <returns>Whether the object can be converted.</returns>
public override bool CanConvertTo(object sourceValue, Type destinationType)
{
return false;
}

/// <summary>
/// Convert from sourceValue to the specified type.
/// </summary>
/// <param name="sourceValue">Value to be converted.</param>
/// <param name="destinationType">Type to which sourceValue should be converted to.</param>
/// <param name="formatProvider">Format provider for the conversion.</param>
/// <param name="ignoreCase">Whether to ignore the case.</param>
/// <returns>The converted object.</returns>
public override object ConvertTo(object sourceValue, Type destinationType, IFormatProvider formatProvider, bool ignoreCase)
{
throw PSTraceSource.NewNotSupportedException();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ namespace Microsoft.PowerShell.Commands
/// This cmdlet start invocation of jobs in background.
/// </summary>
[Cmdlet(VerbsLifecycle.Start, "Job", DefaultParameterSetName = StartJobCommand.ComputerNameParameterSet, HelpUri = "https://go.microsoft.com/fwlink/?LinkID=113405")]
[OutputType(typeof(PSRemotingJob))]
[OutputType(typeof(Job))]
public class StartJobCommand : PSExecutionCmdlet, IDisposable
{
#region Private members
Expand Down
11 changes: 10 additions & 1 deletion src/System.Management.Automation/help/SaveHelpCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -424,8 +424,17 @@ internal override bool ProcessModuleWithCulture(UpdatableHelpModuleInfo module,
#endregion
}

internal sealed class ArgumentToModuleTransformationAttribute : ArgumentTransformationAttribute
/// <summary>
/// Attribute to transform to a module.
/// </summary>
public sealed class ArgumentToModuleTransformationAttribute : ArgumentTransformationAttribute
{
/// <summary>
/// Transform the engineIntrinsics to a module.
/// </summary>
/// <param name="engineIntrinsics">EngineInstrinsics object.</param>
/// <param name="inputData">Value of the attribute.</param>
/// <returns>The object after transformation.</returns>
public override object Transform(EngineIntrinsics engineIntrinsics, object inputData)
{
object argument = PSObject.Base(inputData);
Expand Down
8 changes: 7 additions & 1 deletion src/System.Management.Automation/utils/EncodingUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,14 @@ internal static Encoding Convert(Cmdlet cmdlet, string encoding)
/// When the input data is of type string and is valid to be converted to System.Text.Encoding, we do
/// the conversion and return the converted value. Otherwise, we just return the input data.
/// </summary>
internal sealed class ArgumentToEncodingTransformationAttribute : ArgumentTransformationAttribute
public sealed class ArgumentToEncodingTransformationAttribute : ArgumentTransformationAttribute
{
/// <summary>
/// Transform the argument to type System.Text.Encoding.
/// </summary>
/// <param name="engineIntrinsics">EngineIntrinsics object.</param>
/// <param name="inputData">Value of attribute to be transformmed.</param>
/// <returns>The object after transformation.</returns>
public override object Transform(EngineIntrinsics engineIntrinsics, object inputData)
{
switch (inputData)
Expand Down