From 3a3fb7c75bb5e5aa0ddd2afe4b494876b5081c8f Mon Sep 17 00:00:00 2001 From: Aditya Patwardhan Date: Mon, 10 Dec 2018 13:53:04 -0800 Subject: [PATCH 1/2] Make various types public as they were already visible externally Fix CodeFactor issues --- .../engine/ArgumentTypeConverterAttribute.cs | 8 ++- .../engine/CommonCommandParameters.cs | 14 ++++- .../engine/InternalCommands.cs | 20 +++++-- .../engine/LanguagePrimitives.cs | 54 ++++++++++++++++++- .../engine/remoting/commands/StartJob.cs | 2 +- .../help/SaveHelpCommand.cs | 11 +++- .../utils/EncodingUtils.cs | 8 ++- 7 files changed, 107 insertions(+), 10 deletions(-) diff --git a/src/System.Management.Automation/engine/ArgumentTypeConverterAttribute.cs b/src/System.Management.Automation/engine/ArgumentTypeConverterAttribute.cs index 22a734d9d34..25584a71a7b 100644 --- a/src/System.Management.Automation/engine/ArgumentTypeConverterAttribute.cs +++ b/src/System.Management.Automation/engine/ArgumentTypeConverterAttribute.cs @@ -12,7 +12,7 @@ namespace System.Management.Automation /// /// This is used for automatic conversions to be performed in shell variables. /// - internal sealed class ArgumentTypeConverterAttribute : ArgumentTransformationAttribute + public sealed class ArgumentTypeConverterAttribute : ArgumentTransformationAttribute { /// /// This ctor form is used to initialize shell variables @@ -36,6 +36,12 @@ internal Type TargetType } } + /// + /// Transforms the inputData. + /// + /// Object of type EngineIntrinsics. + /// Object to be transformed. + /// The object after transformation. public override object Transform(EngineIntrinsics engineIntrinsics, object inputData) { return Transform(engineIntrinsics, inputData, false, false); diff --git a/src/System.Management.Automation/engine/CommonCommandParameters.cs b/src/System.Management.Automation/engine/CommonCommandParameters.cs index 78530b6d063..cb4e61bc71d 100644 --- a/src/System.Management.Automation/engine/CommonCommandParameters.cs +++ b/src/System.Management.Automation/engine/CommonCommandParameters.cs @@ -230,8 +230,20 @@ public string PipelineVariable private MshCommandRuntime _commandRuntime; - internal class ValidateVariableName : ValidateArgumentsAttribute + /// + /// Validates variable name to be valid. + /// + public class ValidateVariableName : ValidateArgumentsAttribute { + /// + /// Validate the value of arguments is a valid variable name. + /// + /// + /// The value of the arguments is a variable name to be validated. + /// + /// + /// Instance of EngineIntrinsics class. + /// protected override void Validate(object arguments, EngineIntrinsics engineIntrinsics) { string varName = arguments as string; diff --git a/src/System.Management.Automation/engine/InternalCommands.cs b/src/System.Management.Automation/engine/InternalCommands.cs index e8581e8293d..3ee680d9f8b 100644 --- a/src/System.Management.Automation/engine/InternalCommands.cs +++ b/src/System.Management.Automation/engine/InternalCommands.cs @@ -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. /// - private sealed class ArgumentToVersionTransformationAttribute : ArgumentTransformationAttribute - { + public sealed class ArgumentToVersionTransformationAttribute : ArgumentTransformationAttribute + { + /// + /// Transform the argument to a version. + /// + /// EngineIntrinsics object. + /// Value of attribute to be transformmed. + /// The object after transformation. public override object Transform(EngineIntrinsics engineIntrinsics, object inputData) { object version = PSObject.Base(inputData); @@ -2043,8 +2049,16 @@ public override object Transform(EngineIntrinsics engineIntrinsics, object input } } - private sealed class ValidateVersionAttribute : ValidateArgumentsAttribute + /// + /// Attribute to validate the version. + /// + public sealed class ValidateVersionAttribute : ValidateArgumentsAttribute { + /// + /// Validate the arguments is a valid version. + /// + /// Value of the version argument. + /// EngineIntrinsics object. protected override void Validate(object arguments, EngineIntrinsics engineIntrinsics) { Version version = arguments as Version; diff --git a/src/System.Management.Automation/engine/LanguagePrimitives.cs b/src/System.Management.Automation/engine/LanguagePrimitives.cs index 253cfd4a69a..e9c8bf85020 100644 --- a/src/System.Management.Automation/engine/LanguagePrimitives.cs +++ b/src/System.Management.Automation/engine/LanguagePrimitives.cs @@ -1888,15 +1888,28 @@ public static bool TryConvertTo(object valueToConvert, Type resultType, IFormatP #endregion public type conversion - internal class EnumMultipleTypeConverter : EnumSingleTypeConverter + /// + /// Convert multiple Enum types. + /// + public class EnumMultipleTypeConverter : EnumSingleTypeConverter { + /// + /// Convert from sourceValue to the specified type. + /// + /// value to be converted. + /// type to which sourceValue should be converted to. + /// format provider for the conversion. + /// whether to ignore the case. public override object ConvertFrom(object sourceValue, Type destinationType, IFormatProvider formatProvider, bool ignoreCase) { return EnumSingleTypeConverter.BaseConvertFrom(sourceValue, destinationType, formatProvider, ignoreCase, true); } } - internal class EnumSingleTypeConverter : PSTypeConverter + /// + /// Convert single Enum type. + /// + public class EnumSingleTypeConverter : PSTypeConverter { private class EnumHashEntry { @@ -1976,6 +1989,12 @@ private static EnumHashEntry GetEnumHashEntry(Type enumType) } } + /// + /// Verify if conversion from sourceValue can be done to type destinationType. + /// + /// value to be converted. + /// type to which sourceValue should be converted to. + /// Whether the sourceValue can be converted to destinationType. public override bool CanConvertFrom(object sourceValue, Type destinationType) { return sourceValue is string && destinationType.IsEnum; @@ -2091,11 +2110,28 @@ internal static string EnumValues(Type enumType) return string.Join(CultureInfo.CurrentUICulture.TextInfo.ListSeparator, enumHashEntry.names); } + /// + /// Convert from sourceValue to the specified type. + /// + /// Value to be converted. + /// Type to which sourceValue should be converted to. + /// Format provider for the conversion. + /// Whether to ignore the case. + /// The converted object. public override object ConvertFrom(object sourceValue, Type destinationType, IFormatProvider formatProvider, bool ignoreCase) { return EnumSingleTypeConverter.BaseConvertFrom(sourceValue, destinationType, formatProvider, ignoreCase, false); } + /// + /// Convert from sourceValue to the specified type. + /// + /// Value to be converted. + /// Type to which sourceValue should be converted to. + /// Format provider for the conversion. + /// Whether to ignore the case. + /// Whether to convert multiple values. + /// The converted object. 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"); @@ -2235,11 +2271,25 @@ protected static object BaseConvertFrom(object sourceValue, Type destinationType return Enum.ToObject(destinationType, returnUInt64); } + /// + /// Verify if conversion from sourceValue to destinationType can be done. This is always false. + /// + /// Value to be converted. + /// Type to which sourceValue should be converted to. + /// Whether the object can be converted. public override bool CanConvertTo(object sourceValue, Type destinationType) { return false; } + /// + /// Convert from sourceValue to the specified type. + /// + /// Value to be converted. + /// Type to which sourceValue should be converted to. + /// Format provider for the conversion. + /// Whether to ignore the case. + /// The converted object. public override object ConvertTo(object sourceValue, Type destinationType, IFormatProvider formatProvider, bool ignoreCase) { throw PSTraceSource.NewNotSupportedException(); diff --git a/src/System.Management.Automation/engine/remoting/commands/StartJob.cs b/src/System.Management.Automation/engine/remoting/commands/StartJob.cs index 7e8c160f9d5..d26b5e60994 100644 --- a/src/System.Management.Automation/engine/remoting/commands/StartJob.cs +++ b/src/System.Management.Automation/engine/remoting/commands/StartJob.cs @@ -17,7 +17,7 @@ namespace Microsoft.PowerShell.Commands /// This cmdlet start invocation of jobs in background. /// [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 diff --git a/src/System.Management.Automation/help/SaveHelpCommand.cs b/src/System.Management.Automation/help/SaveHelpCommand.cs index 407aae5b788..9a3180d0c21 100644 --- a/src/System.Management.Automation/help/SaveHelpCommand.cs +++ b/src/System.Management.Automation/help/SaveHelpCommand.cs @@ -424,8 +424,17 @@ internal override bool ProcessModuleWithCulture(UpdatableHelpModuleInfo module, #endregion } - internal sealed class ArgumentToModuleTransformationAttribute : ArgumentTransformationAttribute + /// + /// Attribute to transform to a module. + /// + public sealed class ArgumentToModuleTransformationAttribute : ArgumentTransformationAttribute { + /// + /// Transform the engineIntrinsics to a module. + /// + /// EngineInstrinsics object. + /// Value of the attribute. + /// The object after transformation. public override object Transform(EngineIntrinsics engineIntrinsics, object inputData) { object argument = PSObject.Base(inputData); diff --git a/src/System.Management.Automation/utils/EncodingUtils.cs b/src/System.Management.Automation/utils/EncodingUtils.cs index 2ac22b11c4c..db9f37d24eb 100644 --- a/src/System.Management.Automation/utils/EncodingUtils.cs +++ b/src/System.Management.Automation/utils/EncodingUtils.cs @@ -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. /// - internal sealed class ArgumentToEncodingTransformationAttribute : ArgumentTransformationAttribute + public sealed class ArgumentToEncodingTransformationAttribute : ArgumentTransformationAttribute { + /// + /// Transform the argument to type System.Text.Encoding. + /// + /// EngineIntrinsics object. + /// Value of attribute to be transformmed. + /// The object after transformation. public override object Transform(EngineIntrinsics engineIntrinsics, object inputData) { switch (inputData) From 5b94323a3ec0163d4b40d920605ff727a20eb016 Mon Sep 17 00:00:00 2001 From: Aditya Patwardhan Date: Fri, 25 Jan 2019 11:06:42 -0800 Subject: [PATCH 2/2] Fix CodeFactor issues --- .../engine/LanguagePrimitives.cs | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/System.Management.Automation/engine/LanguagePrimitives.cs b/src/System.Management.Automation/engine/LanguagePrimitives.cs index e9c8bf85020..aeba706030c 100644 --- a/src/System.Management.Automation/engine/LanguagePrimitives.cs +++ b/src/System.Management.Automation/engine/LanguagePrimitives.cs @@ -1896,10 +1896,11 @@ public class EnumMultipleTypeConverter : EnumSingleTypeConverter /// /// Convert from sourceValue to the specified type. /// - /// value to be converted. - /// type to which sourceValue should be converted to. - /// format provider for the conversion. - /// whether to ignore the case. + /// Value to be converted. + /// Type to which sourceValue should be converted to. + /// Format provider for the conversion. + /// Whether to ignore the case. + /// The object after conversion. public override object ConvertFrom(object sourceValue, Type destinationType, IFormatProvider formatProvider, bool ignoreCase) { return EnumSingleTypeConverter.BaseConvertFrom(sourceValue, destinationType, formatProvider, ignoreCase, true); @@ -1992,9 +1993,9 @@ private static EnumHashEntry GetEnumHashEntry(Type enumType) /// /// Verify if conversion from sourceValue can be done to type destinationType. /// - /// value to be converted. - /// type to which sourceValue should be converted to. - /// Whether the sourceValue can be converted to destinationType. + /// Value to be converted. + /// Type to which sourceValue should be converted to. + /// Whether the sourceValue can be converted to destinationType. public override bool CanConvertFrom(object sourceValue, Type destinationType) { return sourceValue is string && destinationType.IsEnum;