From 192e3eb71e53457f533460e4b96fdadaa5620e53 Mon Sep 17 00:00:00 2001 From: Ilya Date: Wed, 14 Aug 2019 11:36:26 +0500 Subject: [PATCH 1/4] Fix style issues in InternalCommands.cs --- .../engine/InternalCommands.cs | 649 +++++++++++++----- 1 file changed, 466 insertions(+), 183 deletions(-) diff --git a/src/System.Management.Automation/engine/InternalCommands.cs b/src/System.Management.Automation/engine/InternalCommands.cs index 2b901b782ca..f2a9e033d53 100644 --- a/src/System.Management.Automation/engine/InternalCommands.cs +++ b/src/System.Management.Automation/engine/InternalCommands.cs @@ -23,7 +23,7 @@ namespace Microsoft.PowerShell.Commands /// /// A thin wrapper over a property-getting Callsite, to allow reuse when possible. /// - struct DynamicPropertyGetter + internal struct DynamicPropertyGetter { private CallSite> _getValueDynamicSite; @@ -37,7 +37,6 @@ public object GetValue(PSObject inputObject, string propertyName) // If wildcards are involved, the resolved property name could potentially // be different on every object... but probably not, so we'll attempt to // reuse the callsite if possible. - if (!propertyName.Equals(_lastUsedPropertyName, StringComparison.OrdinalIgnoreCase)) { _lastUsedPropertyName = propertyName; @@ -91,81 +90,93 @@ public PSObject InputObject private List _scripts = new List(); /// - /// The script block to apply in begin processing. + /// Gets or sets the script block to apply in begin processing. /// [Parameter(ParameterSetName = ForEachObjectCommand.ScriptBlockSet)] public ScriptBlock Begin { - set + get { - _scripts.Insert(0, value); + return null; } - get + set { - return null; + _scripts.Insert(0, value); } } /// - /// The script block to apply. + /// Gets or sets the script block to apply. /// [Parameter(Mandatory = true, Position = 0, ParameterSetName = ForEachObjectCommand.ScriptBlockSet)] [AllowNull] [AllowEmptyCollection] public ScriptBlock[] Process { + get + { + return null; + } + set { if (value == null) + { _scripts.Add(null); + } else + { _scripts.AddRange(value); - } - - get - { - return null; + } } } private ScriptBlock _endScript; private bool _setEndScript; + /// - /// The script block to apply in complete processing. + /// Gets or sets the script block to apply in complete processing. /// [Parameter(ParameterSetName = ForEachObjectCommand.ScriptBlockSet)] public ScriptBlock End { - set + get { - _endScript = value; - _setEndScript = true; + return _endScript; } - get + set { - return _endScript; + _endScript = value; + _setEndScript = true; } } /// - /// The remaining script blocks to apply. + /// Gets or sets the remaining script blocks to apply. /// [Parameter(ParameterSetName = ForEachObjectCommand.ScriptBlockSet, ValueFromRemainingArguments = true)] [AllowNull] [AllowEmptyCollection] public ScriptBlock[] RemainingScripts { + get + { + return null; + } + set { if (value == null) + { _scripts.Add(null); + } else + { _scripts.AddRange(value); + } } - - get { return null; } } private int _start, _end; @@ -175,16 +186,22 @@ public ScriptBlock[] RemainingScripts #region PropertyAndMethodSet /// - /// The property or method name. + /// Gets or sets the property or method name. /// [Parameter(Mandatory = true, Position = 0, ParameterSetName = ForEachObjectCommand.PropertyAndMethodSet)] [ValidateTrustedData] [ValidateNotNullOrEmpty] public string MemberName { - set { _propertyOrMethodName = value; } + set + { + _propertyOrMethodName = value; + } - get { return _propertyOrMethodName; } + get + { + return _propertyOrMethodName; + } } private string _propertyOrMethodName; @@ -341,7 +358,7 @@ public void Dispose() } #endregion - + #region Private Methods #region PSTasks @@ -375,7 +392,7 @@ private void InitParallelParameterSet() allowUsingExpression, this.Context, null); - + // Validate using values map, which is a map of '$using:' variables referenced in the script. // Script block variables are not allowed since their behavior is undefined outside the runspace // in which they were created. @@ -499,6 +516,7 @@ private void EndBlockParameterSet() { if (_endScript == null) return; + } var emptyArray = Array.Empty(); _endScript.InvokeUsingCmdlet( @@ -890,8 +908,9 @@ private void MethodCallWithArguments() { // resolve the name ReadOnlyPSMemberInfoCollection methods = - _inputObject.Members.Match(_propertyOrMethodName, - PSMemberTypes.Methods | PSMemberTypes.ParameterizedProperty); + _inputObject.Members.Match( + _propertyOrMethodName, + PSMemberTypes.Methods | PSMemberTypes.ParameterizedProperty); Dbg.Assert(methods != null, "The return value of Members.Match should never be null."); if (methods.Count > 1) @@ -903,15 +922,23 @@ private void MethodCallWithArguments() possibleMatches.AppendFormat(CultureInfo.InvariantCulture, " {0}", item.Name); } - WriteError(GenerateNameParameterError("Name", InternalCommandStrings.AmbiguousMethodName, - "AmbiguousMethodName", _inputObject, - _propertyOrMethodName, possibleMatches)); + WriteError(GenerateNameParameterError( + "Name", + InternalCommandStrings.AmbiguousMethodName, + "AmbiguousMethodName", + _inputObject, + _propertyOrMethodName, + possibleMatches)); } else if (methods.Count == 0 || !(methods[0] is PSMethodInfo)) { // write error record: method no found - WriteError(GenerateNameParameterError("Name", InternalCommandStrings.MethodNotFound, - "MethodNotFound", _inputObject, _propertyOrMethodName)); + WriteError(GenerateNameParameterError( + "Name", + InternalCommandStrings.MethodNotFound, + "MethodNotFound", + _inputObject, + _propertyOrMethodName)); } else { @@ -955,8 +982,8 @@ private void MethodCallWithArguments() /// /// Get the string representation of the passed-in object. /// - /// - /// + /// Source object. + /// String representation of the source object. private static string GetStringRepresentation(object obj) { string objInString; @@ -983,7 +1010,7 @@ private static string GetStringRepresentation(object obj) /// Get the value by taking _propertyOrMethodName as the key, if the /// input object is a IDictionary. /// - /// + /// True if success. private bool GetValueFromIDictionaryInput() { object target = PSObject.Base(_inputObject); @@ -993,8 +1020,10 @@ private bool GetValueFromIDictionaryInput() { if (hash != null && hash.Contains(_propertyOrMethodName)) { - string keyAction = string.Format(CultureInfo.InvariantCulture, - InternalCommandStrings.ForEachObjectKeyAction, _propertyOrMethodName); + string keyAction = string.Format( + CultureInfo.InvariantCulture, + InternalCommandStrings.ForEachObjectKeyAction, + _propertyOrMethodName); if (ShouldProcess(_targetString, keyAction)) { object result = hash[_propertyOrMethodName]; @@ -1017,7 +1046,7 @@ private bool GetValueFromIDictionaryInput() /// Unroll the object to be output. If it's of type IEnumerator, unroll and output it /// by calling WriteOutIEnumerator. If it's not, unroll and output it by calling WriteObject(obj, true) /// - /// + /// Source object. private void WriteToPipelineWithUnrolling(object obj) { IEnumerator objAsEnumerator = LanguagePrimitives.GetEnumerator(obj); @@ -1034,7 +1063,7 @@ private void WriteToPipelineWithUnrolling(object obj) /// /// Unroll an IEnumerator and output all entries. /// - /// + /// Source list. private void WriteOutIEnumerator(IEnumerator list) { if (list != null) @@ -1055,7 +1084,8 @@ private void WriteOutIEnumerator(IEnumerator list) /// Check if the language mode is the restrictedLanguageMode before invoking a method. /// Write out error message and return true if we are in restrictedLanguageMode. /// - /// + /// Source object. + /// True if we are in restrictedLanguageMode. private bool BlockMethodInLanguageMode(Object inputObject) { // Cannot invoke a method in RestrictedLanguage mode @@ -1136,39 +1166,46 @@ internal static ErrorRecord GenerateNameParameterError(string paraName, string r public sealed class WhereObjectCommand : PSCmdlet { /// - /// This parameter specifies the current pipeline object. + /// Gets or sets the current pipeline object. /// [Parameter(ValueFromPipeline = true)] public PSObject InputObject { - set { _inputObject = value; } + get + { + return _inputObject; + } - get { return _inputObject; } + set + { + _inputObject = value; + } } private PSObject _inputObject = AutomationNull.Value; private ScriptBlock _script; /// - /// The script block to apply. + /// Gets or sets the script block to apply. /// [Parameter(Mandatory = true, Position = 0, ParameterSetName = "ScriptBlockSet")] public ScriptBlock FilterScript { - set + get { - _script = value; + return _script; } - get + set { - return _script; + _script = value; } } private string _property; + /// - /// The property to retrieve value. + /// Gets or sets the property to retrieve value. /// [Parameter(Mandatory = true, Position = 0, ParameterSetName = "EqualSet")] [Parameter(Mandatory = true, Position = 0, ParameterSetName = "CaseSensitiveEqualSet")] @@ -1204,14 +1241,21 @@ public ScriptBlock FilterScript [ValidateNotNullOrEmpty] public string Property { - set { _property = value; } + get + { + return _property; + } - get { return _property; } + set + { + _property = value; + } } private object _convertedValue; private object _value = true; private bool _valueNotSpecified = true; + /// /// The value to compare against. /// @@ -1247,13 +1291,16 @@ public string Property [Parameter(Position = 1, ParameterSetName = "IsNotSet")] public object Value { + get + { + return _value; + } + set { _value = value; _valueNotSpecified = false; } - - get { return _value; } } #region binary operator parameters @@ -1265,363 +1312,546 @@ public object Value private bool _forceBooleanEvaluation = true; /// - /// Binary operator -Equal + /// Gets or sets binary operator -Equal /// It's the default parameter set, so -EQ is not mandatory. /// [Parameter(ParameterSetName = "EqualSet")] [Alias("IEQ")] public SwitchParameter EQ { + get + { + return _binaryOperator == TokenKind.Ieq; + } + set { _binaryOperator = TokenKind.Ieq; _forceBooleanEvaluation = false; } - - get { return _binaryOperator == TokenKind.Ieq; } } /// - /// Case sensitive binary operator -ceq. + /// Gets or sets case sensitive binary operator -ceq. /// [Parameter(Mandatory = true, ParameterSetName = "CaseSensitiveEqualSet")] public SwitchParameter CEQ { - set { _binaryOperator = TokenKind.Ceq; } + get + { + return _binaryOperator == TokenKind.Ceq; + } - get { return _binaryOperator == TokenKind.Ceq; } + set + { + _binaryOperator = TokenKind.Ceq; + } } /// - /// Binary operator -NotEqual. + /// Gets or sets binary operator -NotEqual. /// [Parameter(Mandatory = true, ParameterSetName = "NotEqualSet")] [Alias("INE")] public SwitchParameter NE { - set { _binaryOperator = TokenKind.Ine; } + get + { + return _binaryOperator == TokenKind.Ine; + } - get { return _binaryOperator == TokenKind.Ine; } + set + { + _binaryOperator = TokenKind.Ine; + } } /// - /// Case sensitive binary operator -cne. + /// Gets or sets case sensitive binary operator -cne. /// [Parameter(Mandatory = true, ParameterSetName = "CaseSensitiveNotEqualSet")] public SwitchParameter CNE { - set { _binaryOperator = TokenKind.Cne; } + get + { + return _binaryOperator == TokenKind.Cne; + } - get { return _binaryOperator == TokenKind.Cne; } + set + { + _binaryOperator = TokenKind.Cne; + } } /// - /// Binary operator -GreaterThan. + /// Gets or sets binary operator -GreaterThan. /// [Parameter(Mandatory = true, ParameterSetName = "GreaterThanSet")] [Alias("IGT")] public SwitchParameter GT { - set { _binaryOperator = TokenKind.Igt; } + get + { + return _binaryOperator == TokenKind.Igt; + } - get { return _binaryOperator == TokenKind.Igt; } + set + { + _binaryOperator = TokenKind.Igt; + } } /// - /// Case sensitive binary operator -cgt. + /// Gets or sets case sensitive binary operator -cgt. /// [Parameter(Mandatory = true, ParameterSetName = "CaseSensitiveGreaterThanSet")] public SwitchParameter CGT { - set { _binaryOperator = TokenKind.Cgt; } + get + { + return _binaryOperator == TokenKind.Cgt; + } - get { return _binaryOperator == TokenKind.Cgt; } + set + { + _binaryOperator = TokenKind.Cgt; + } } /// - /// Binary operator -LessThan. + /// Gets or sets binary operator -LessThan. /// [Parameter(Mandatory = true, ParameterSetName = "LessThanSet")] [Alias("ILT")] public SwitchParameter LT { - set { _binaryOperator = _binaryOperator = TokenKind.Ilt; } + get + { + return _binaryOperator == TokenKind.Ilt; + } - get { return _binaryOperator == TokenKind.Ilt; } + set + { + _binaryOperator = _binaryOperator = TokenKind.Ilt; + } } /// - /// Case sensitive binary operator -clt. + /// Gets -sets case sensitive binary operator -clt. /// [Parameter(Mandatory = true, ParameterSetName = "CaseSensitiveLessThanSet")] public SwitchParameter CLT { - set { _binaryOperator = TokenKind.Clt; } + get + { + return _binaryOperator == TokenKind.Clt; + } - get { return _binaryOperator == TokenKind.Clt; } + set + { + _binaryOperator = TokenKind.Clt; + } } /// - /// Binary operator -GreaterOrEqual. + /// Gets or sets binary operator -GreaterOrEqual. /// [Parameter(Mandatory = true, ParameterSetName = "GreaterOrEqualSet")] [Alias("IGE")] public SwitchParameter GE { - set { _binaryOperator = TokenKind.Ige; } + get + { + return _binaryOperator == TokenKind.Ige; + } - get { return _binaryOperator == TokenKind.Ige; } + set + { + _binaryOperator = TokenKind.Ige; + } } /// - /// Case sensitive binary operator -cge. + /// Gets or sets case sensitive binary operator -cge. /// [Parameter(Mandatory = true, ParameterSetName = "CaseSensitiveGreaterOrEqualSet")] public SwitchParameter CGE { - set { _binaryOperator = TokenKind.Cge; } + get + { + return _binaryOperator == TokenKind.Cge; + } - get { return _binaryOperator == TokenKind.Cge; } + set + { + _binaryOperator = TokenKind.Cge; + } } /// - /// Binary operator -LessOrEqual. + /// Gets or sets binary operator -LessOrEqual. /// [Parameter(Mandatory = true, ParameterSetName = "LessOrEqualSet")] [Alias("ILE")] public SwitchParameter LE { - set { _binaryOperator = TokenKind.Ile; } + get + { + return _binaryOperator == TokenKind.Ile; + } - get { return _binaryOperator == TokenKind.Ile; } + set + { + _binaryOperator = TokenKind.Ile; + } } /// - /// Case sensitive binary operator -cle. + /// Gets or sets case sensitive binary operator -cle. /// [Parameter(Mandatory = true, ParameterSetName = "CaseSensitiveLessOrEqualSet")] public SwitchParameter CLE { - set { _binaryOperator = TokenKind.Cle; } + get + { + return _binaryOperator == TokenKind.Cle; + } - get { return _binaryOperator == TokenKind.Cle; } + set + { + _binaryOperator = TokenKind.Cle; + } } /// - /// Binary operator -Like. + ///Gets or sets binary operator -Like. /// [Parameter(Mandatory = true, ParameterSetName = "LikeSet")] [Alias("ILike")] public SwitchParameter Like { - set { _binaryOperator = TokenKind.Ilike; } + get + { + return _binaryOperator == TokenKind.Ilike; + } - get { return _binaryOperator == TokenKind.Ilike; } + set + { + _binaryOperator = TokenKind.Ilike; + } } /// - /// Case sensitive binary operator -clike. + /// Gets or sets case sensitive binary operator -clike. /// [Parameter(Mandatory = true, ParameterSetName = "CaseSensitiveLikeSet")] public SwitchParameter CLike { - set { _binaryOperator = TokenKind.Clike; } + get + { + return _binaryOperator == TokenKind.Clike; + } - get { return _binaryOperator == TokenKind.Clike; } + set + { + _binaryOperator = TokenKind.Clike; + } } /// - /// Binary operator -NotLike. + /// Gets or sets binary operator -NotLike. /// [Parameter(Mandatory = true, ParameterSetName = "NotLikeSet")] [Alias("INotLike")] public SwitchParameter NotLike { - set { _binaryOperator = TokenKind.Inotlike; } + get + { + return false; + } - get { return false; } + set + { + _binaryOperator = TokenKind.Inotlike; + } } /// - /// Case sensitive binary operator -cnotlike. + /// Gets or sets case sensitive binary operator -cnotlike. /// [Parameter(Mandatory = true, ParameterSetName = "CaseSensitiveNotLikeSet")] public SwitchParameter CNotLike { - set { _binaryOperator = TokenKind.Cnotlike; } + get + { + return _binaryOperator == TokenKind.Cnotlike; + } - get { return _binaryOperator == TokenKind.Cnotlike; } + set + { + _binaryOperator = TokenKind.Cnotlike; + } } /// - /// Binary operator -Match. + /// Get or sets binary operator -Match. /// [Parameter(Mandatory = true, ParameterSetName = "MatchSet")] [Alias("IMatch")] public SwitchParameter Match { - set { _binaryOperator = TokenKind.Imatch; } + get + { + return _binaryOperator == TokenKind.Imatch; + } - get { return _binaryOperator == TokenKind.Imatch; } + set + { + _binaryOperator = TokenKind.Imatch; + } } /// - /// Case sensitive binary operator -cmatch. + /// Gets or sets case sensitive binary operator -cmatch. /// [Parameter(Mandatory = true, ParameterSetName = "CaseSensitiveMatchSet")] public SwitchParameter CMatch { - set { _binaryOperator = TokenKind.Cmatch; } + get + { + return _binaryOperator == TokenKind.Cmatch; + } - get { return _binaryOperator == TokenKind.Cmatch; } + set + { + _binaryOperator = TokenKind.Cmatch; + } } /// - /// Binary operator -NotMatch. + /// Gets or sets binary operator -NotMatch. /// [Parameter(Mandatory = true, ParameterSetName = "NotMatchSet")] [Alias("INotMatch")] public SwitchParameter NotMatch { - set { _binaryOperator = TokenKind.Inotmatch; } + get + { + return _binaryOperator == TokenKind.Inotmatch; + } - get { return _binaryOperator == TokenKind.Inotmatch; } + set + { + _binaryOperator = TokenKind.Inotmatch; + } } /// - /// Case sensitive binary operator -cnotmatch. + /// Gets or sets case sensitive binary operator -cnotmatch. /// [Parameter(Mandatory = true, ParameterSetName = "CaseSensitiveNotMatchSet")] public SwitchParameter CNotMatch { - set { _binaryOperator = TokenKind.Cnotmatch; } + get + { + return _binaryOperator == TokenKind.Cnotmatch; + } - get { return _binaryOperator == TokenKind.Cnotmatch; } + set + { + _binaryOperator = TokenKind.Cnotmatch; + } } /// - /// Binary operator -Contains. + /// Gets or sets binary operator -Contains. /// [Parameter(Mandatory = true, ParameterSetName = "ContainsSet")] [Alias("IContains")] public SwitchParameter Contains { - set { _binaryOperator = TokenKind.Icontains; } + get + { + return _binaryOperator == TokenKind.Icontains; + } - get { return _binaryOperator == TokenKind.Icontains; } + set + { + _binaryOperator = TokenKind.Icontains; + } } /// - /// Case sensitive binary operator -ccontains. + /// Gets or sets case sensitive binary operator -ccontains. /// [Parameter(Mandatory = true, ParameterSetName = "CaseSensitiveContainsSet")] public SwitchParameter CContains { - set { _binaryOperator = TokenKind.Ccontains; } + get + { + return _binaryOperator == TokenKind.Ccontains; + } - get { return _binaryOperator == TokenKind.Ccontains; } + set + { + _binaryOperator = TokenKind.Ccontains; + } } /// - /// Binary operator -NotContains. + /// Gets or sets binary operator -NotContains. /// [Parameter(Mandatory = true, ParameterSetName = "NotContainsSet")] [Alias("INotContains")] public SwitchParameter NotContains { - set { _binaryOperator = TokenKind.Inotcontains; } + get + { + return _binaryOperator == TokenKind.Inotcontains; + } - get { return _binaryOperator == TokenKind.Inotcontains; } + set + { + _binaryOperator = TokenKind.Inotcontains; + } } /// - /// Case sensitive binary operator -cnotcontains. + /// Gets or sets case sensitive binary operator -cnotcontains. /// [Parameter(Mandatory = true, ParameterSetName = "CaseSensitiveNotContainsSet")] public SwitchParameter CNotContains { - set { _binaryOperator = TokenKind.Cnotcontains; } + get + { + return _binaryOperator == TokenKind.Cnotcontains; + } - get { return _binaryOperator == TokenKind.Cnotcontains; } + set + { + _binaryOperator = TokenKind.Cnotcontains; + } } /// - /// Binary operator -In. + /// Gets or sets binary operator -In. /// [Parameter(Mandatory = true, ParameterSetName = "InSet")] [Alias("IIn")] public SwitchParameter In { - set { _binaryOperator = TokenKind.In; } + get + { + return _binaryOperator == TokenKind.In; + } - get { return _binaryOperator == TokenKind.In; } + set + { + _binaryOperator = TokenKind.In; + } } /// - /// Case sensitive binary operator -cin. + /// Gets or sets case sensitive binary operator -cin. /// [Parameter(Mandatory = true, ParameterSetName = "CaseSensitiveInSet")] public SwitchParameter CIn { - set { _binaryOperator = TokenKind.Cin; } + get + { + return _binaryOperator == TokenKind.Cin; + } - get { return _binaryOperator == TokenKind.Cin; } + set + { + _binaryOperator = TokenKind.Cin; + } } /// - /// Binary operator -NotIn. + /// Gets or sets binary operator -NotIn. /// [Parameter(Mandatory = true, ParameterSetName = "NotInSet")] [Alias("INotIn")] public SwitchParameter NotIn { - set { _binaryOperator = TokenKind.Inotin; } + get + { + return _binaryOperator == TokenKind.Inotin; + } - get { return _binaryOperator == TokenKind.Inotin; } + set + { + _binaryOperator = TokenKind.Inotin; + } } /// - /// Case sensitive binary operator -cnotin. + /// Gets or sets case sensitive binary operator -cnotin. /// [Parameter(Mandatory = true, ParameterSetName = "CaseSensitiveNotInSet")] public SwitchParameter CNotIn { - set { _binaryOperator = TokenKind.Cnotin; } + get + { + return _binaryOperator == TokenKind.Cnotin; + } - get { return _binaryOperator == TokenKind.Cnotin; } + set + { + _binaryOperator = TokenKind.Cnotin; + } } /// - /// Binary operator -Is. + /// Gets or sets binary operator -Is. /// [Parameter(Mandatory = true, ParameterSetName = "IsSet")] public SwitchParameter Is { - set { _binaryOperator = TokenKind.Is; } + get + { + return _binaryOperator == TokenKind.Is; + } - get { return _binaryOperator == TokenKind.Is; } + set + { + _binaryOperator = TokenKind.Is; + } } /// - /// Binary operator -IsNot. + /// Gets or sets binary operator -IsNot. /// [Parameter(Mandatory = true, ParameterSetName = "IsNotSet")] public SwitchParameter IsNot { - set { _binaryOperator = TokenKind.IsNot; } + get + { + return _binaryOperator == TokenKind.IsNot; + } - get { return _binaryOperator == TokenKind.IsNot; } + set + { + _binaryOperator = TokenKind.IsNot; + } } /// - /// Binary operator -Not. + /// Gets or sets binary operator -Not. /// [Parameter(Mandatory = true, ParameterSetName = "Not")] public SwitchParameter Not { - set { _binaryOperator = TokenKind.Not; } + get + { + return _binaryOperator == TokenKind.Not; + } - get { return _binaryOperator == TokenKind.Not; } + set + { + _binaryOperator = TokenKind.Not; + } } #endregion binary operator parameters @@ -1649,20 +1879,21 @@ private static Func GetCallSiteDelegateBoolean(Expressio private static Tuple>, CallSite>> GetContainsCallSites(bool ignoreCase) { var enumerableSite = CallSite>.Create(PSEnumerableBinder.Get()); - var eqSite = + var equalSite = CallSite>.Create(PSBinaryOperationBinder.Get( ExpressionType.Equal, ignoreCase, scalarCompare: true)); - return Tuple.Create(enumerableSite, eqSite); + return Tuple.Create(enumerableSite, equalSite); } private void CheckLanguageMode() { if (Context.LanguageMode.Equals(PSLanguageMode.RestrictedLanguage)) { - string message = string.Format(CultureInfo.InvariantCulture, - InternalCommandStrings.OperationNotAllowedInRestrictedLanguageMode, - _binaryOperator); + string message = string.Format( + CultureInfo.InvariantCulture, + InternalCommandStrings.OperationNotAllowedInRestrictedLanguageMode, + _binaryOperator); PSInvalidOperationException exception = new PSInvalidOperationException(message); ThrowTerminatingError(new ErrorRecord(exception, "OperationNotAllowedInRestrictedLanguageMode", ErrorCategory.InvalidOperation, null)); @@ -1673,7 +1904,9 @@ private object GetLikeRHSOperand(object operand) { var val = operand as string; if (val == null) + { return operand; + } var wildcardOptions = _binaryOperator == TokenKind.Ilike || _binaryOperator == TokenKind.Inotlike ? WildcardOptions.IgnoreCase @@ -1685,7 +1918,9 @@ private object GetLikeRHSOperand(object operand) protected override void BeginProcessing() { if (_script != null) + { return; + } switch (_binaryOperator) { @@ -1772,6 +2007,7 @@ protected override void BeginProcessing() case TokenKind.Not: _operationDelegate = GetCallSiteDelegateBoolean(ExpressionType.NotEqual, ignoreCase: true); break; + // the second to last parameter in ContainsOperator has flipped semantics compared to others. // "true" means "contains" while "false" means "notcontains" case TokenKind.Icontains: @@ -1882,7 +2118,9 @@ protected override void BeginProcessing() protected override void ProcessRecord() { if (_inputObject == AutomationNull.Value) + { return; + } if (_script != null) { @@ -1928,7 +2166,10 @@ protected override void ProcessRecord() bool strictModeWithError = false; object lvalue = GetValue(ref strictModeWithError); - if (strictModeWithError) return; + if (strictModeWithError) + { + return; + } try { @@ -2045,9 +2286,12 @@ private object GetValue(ref bool error) } else if (Context.IsStrictVersion(2)) { - WriteError(ForEachObjectCommand.GenerateNameParameterError("Property", - InternalCommandStrings.PropertyNotFound, - "PropertyNotFound", _inputObject, _property)); + WriteError(ForEachObjectCommand.GenerateNameParameterError( + "Property", + InternalCommandStrings.PropertyNotFound, + "PropertyNotFound", + _inputObject, + _property)); error = true; } } @@ -2094,7 +2338,6 @@ private object GetValue(ref bool error) // showing "The property 'Blarg' does not exist" (case 1) errors than to // suppress "FooException thrown when accessing Bloop property" (case // 2) errors. - if (isBlindDynamicAccess && Context.IsStrictVersion(2)) { WriteError(new ErrorRecord(ex, @@ -2118,7 +2361,7 @@ private object GetValue(ref bool error) /// /// Get the matched PSMembers. /// - /// + /// Matched PSMembers. private ReadOnlyPSMemberInfoCollection GetMatchMembers() { if (!WildcardPattern.ContainsWildcardCharacters(_property)) @@ -2146,54 +2389,78 @@ private ReadOnlyPSMemberInfoCollection GetMatchMembers() public sealed class SetPSDebugCommand : PSCmdlet { /// - /// Sets the script tracing level. + /// Gets or sets the script tracing level. /// [Parameter(ParameterSetName = "on")] [ValidateRange(0, 2)] public int Trace { - set { _trace = value; } + get + { + return _trace; + } - get { return _trace; } + set + { + _trace = value; + } } private int _trace = -1; /// - /// Turns stepping on and off. + /// Gets or sets stepping on and off. /// [Parameter(ParameterSetName = "on")] public SwitchParameter Step { - set { _step = value; } + get + { + return (SwitchParameter)_step; + } - get { return (SwitchParameter)_step; } + set + { + _step = value; + } } private bool? _step; /// - /// Turns strict mode on and off. + /// Gets or sets strict mode on and off. /// [Parameter(ParameterSetName = "on")] public SwitchParameter Strict { - set { _strict = value; } + get + { + return (SwitchParameter)_strict; + } - get { return (SwitchParameter)_strict; } + set + { + _strict = value; + } } private bool? _strict; /// - /// Turns all script debugging features off. + /// Gets or sets all script debugging features off. /// [Parameter(ParameterSetName = "off")] public SwitchParameter Off { - get { return _off; } + get + { + return _off; + } - set { _off = value; } + set + { + _off = value; + } } private bool _off; @@ -2215,9 +2482,12 @@ protected override void BeginProcessing() { Context.Debugger.EnableTracing(_trace, _step); } + // Version 0 is the same as off if (_strict != null) + { Context.EngineSessionState.GlobalScope.StrictModeVersion = new Version((bool)_strict ? 1 : 0, 0); + } } } } @@ -2245,15 +2515,20 @@ protected override void BeginProcessing() public class SetStrictModeCommand : PSCmdlet { /// - /// The following is the definition of the input parameter "Off". - /// Turns strict mode off. + /// Gets or sets strict mode off. /// [Parameter(ParameterSetName = "Off", Mandatory = true)] public SwitchParameter Off { - get { return _off; } + get + { + return _off; + } - set { _off = value; } + set + { + _off = value; + } } private SwitchParameter _off; @@ -2310,25 +2585,33 @@ protected override void Validate(object arguments, EngineIntrinsics engineIntrin if (version == null || !PSVersionInfo.IsValidPSVersion(version)) { // No conversion succeeded so throw and exception... - throw new ValidationMetadataException("InvalidPSVersion", - null, Metadata.ValidateVersionFailure, arguments); + throw new ValidationMetadataException( + "InvalidPSVersion", + null, + Metadata.ValidateVersionFailure, + arguments); } } } /// - /// The following is the definition of the input parameter "Version". - /// Turns strict mode in the current scope. + /// Gets or sets strict mode in the current scope. /// [Parameter(ParameterSetName = "Version", Mandatory = true)] - [ArgumentToVersionTransformation()] - [ValidateVersion()] + [ArgumentToVersionTransformation] + [ValidateVersion] [Alias("v")] public Version Version { - get { return _version; } + get + { + return _version; + } - set { _version = value; } + set + { + _version = value; + } } private Version _version; From b7df9c65990625e445cf5f17ff8be34f84803911 Mon Sep 17 00:00:00 2001 From: Ilya Date: Wed, 14 Aug 2019 11:53:05 +0500 Subject: [PATCH 2/4] Fix typo --- src/System.Management.Automation/engine/InternalCommands.cs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/System.Management.Automation/engine/InternalCommands.cs b/src/System.Management.Automation/engine/InternalCommands.cs index f2a9e033d53..4a3bd716a86 100644 --- a/src/System.Management.Automation/engine/InternalCommands.cs +++ b/src/System.Management.Automation/engine/InternalCommands.cs @@ -515,6 +515,7 @@ private void StopParallelProcessing() private void EndBlockParameterSet() { if (_endScript == null) + { return; } From 04c4d3451e21eb9a7310f9965905777927e3a7e5 Mon Sep 17 00:00:00 2001 From: Ilya Date: Wed, 14 Aug 2019 12:19:07 +0500 Subject: [PATCH 3/4] Fix typo 2 --- .../engine/InternalCommands.cs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/System.Management.Automation/engine/InternalCommands.cs b/src/System.Management.Automation/engine/InternalCommands.cs index 4a3bd716a86..2f7d165e622 100644 --- a/src/System.Management.Automation/engine/InternalCommands.cs +++ b/src/System.Management.Automation/engine/InternalCommands.cs @@ -193,14 +193,14 @@ public ScriptBlock[] RemainingScripts [ValidateNotNullOrEmpty] public string MemberName { - set + get { - _propertyOrMethodName = value; + return _propertyOrMethodName; } - get + set { - return _propertyOrMethodName; + _propertyOrMethodName = value; } } @@ -1508,7 +1508,7 @@ public SwitchParameter LE } /// - /// Gets or sets case sensitive binary operator -cle. + /// Gets or sets case sensitive binary operator -cle. /// [Parameter(Mandatory = true, ParameterSetName = "CaseSensitiveLessOrEqualSet")] public SwitchParameter CLE From 055137fa29a0b91e81906afbd08aa1f2a88ac5a8 Mon Sep 17 00:00:00 2001 From: Ilya Date: Wed, 14 Aug 2019 12:45:19 +0500 Subject: [PATCH 4/4] Remove extra assignment --- src/System.Management.Automation/engine/InternalCommands.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/System.Management.Automation/engine/InternalCommands.cs b/src/System.Management.Automation/engine/InternalCommands.cs index 2f7d165e622..010f1e1f9cf 100644 --- a/src/System.Management.Automation/engine/InternalCommands.cs +++ b/src/System.Management.Automation/engine/InternalCommands.cs @@ -1433,7 +1433,7 @@ public SwitchParameter LT set { - _binaryOperator = _binaryOperator = TokenKind.Ilt; + _binaryOperator = TokenKind.Ilt; } }