From fe4febeccbfd3713263ba7cbf5ced8c8c60c8086 Mon Sep 17 00:00:00 2001 From: Ron Green <11993626+georgettica@users.noreply.github.com> Date: Sat, 17 Oct 2020 19:41:46 +0300 Subject: [PATCH 1/2] fix(utility): nullable formatting --- .../utility/FormatAndOutput/format-wide/Format-Wide.cs | 10 +++++----- .../commands/utility/GetRandomCommand.cs | 2 +- .../commands/utility/OrderObjectBase.cs | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/FormatAndOutput/format-wide/Format-Wide.cs b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/FormatAndOutput/format-wide/Format-Wide.cs index 5927244d896..ef4176303bd 100644 --- a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/FormatAndOutput/format-wide/Format-Wide.cs +++ b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/FormatAndOutput/format-wide/Format-Wide.cs @@ -50,7 +50,7 @@ public SwitchParameter AutoSize get { if (_autosize.HasValue) - return _autosize.Value; + return _autosize; return false; } @@ -70,7 +70,7 @@ public int Column get { if (_column.HasValue) - return _column.Value; + return _column; return -1; } @@ -106,7 +106,7 @@ internal override FormattingCommandLineParameters GetCommandLineParameters() // we cannot specify -column and -autosize, they are mutually exclusive if (_autosize.HasValue && _column.HasValue) { - if (_autosize.Value) + if (_autosize) { // the user specified -autosize:true AND a column number string msg = StringUtil.Format(FormatAndOut_format_xxx.CannotSpecifyAutosizeAndColumnsError); @@ -132,13 +132,13 @@ internal override FormattingCommandLineParameters GetCommandLineParameters() parameters.expansion = ProcessExpandParameter(); if (_autosize.HasValue) - parameters.autosize = _autosize.Value; + parameters.autosize = _autosize; WideSpecificParameters wideSpecific = new WideSpecificParameters(); parameters.shapeParameters = wideSpecific; if (_column.HasValue) { - wideSpecific.columns = _column.Value; + wideSpecific.columns = _column; } return parameters; diff --git a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/GetRandomCommand.cs b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/GetRandomCommand.cs index 01cf6534c48..baafb6a6726 100644 --- a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/GetRandomCommand.cs +++ b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/GetRandomCommand.cs @@ -396,7 +396,7 @@ protected override void BeginProcessing() { if (SetSeed.HasValue) { - Generator = new PolymorphicRandomNumberGenerator(SetSeed.Value); + Generator = new PolymorphicRandomNumberGenerator(SetSeed); } if (EffectiveParameterSet == MyParameterSet.RandomNumber) diff --git a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/OrderObjectBase.cs b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/OrderObjectBase.cs index c2ebc9261a1..fe6cc88d4b9 100644 --- a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/OrderObjectBase.cs +++ b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/OrderObjectBase.cs @@ -685,7 +685,7 @@ internal static OrderByPropertyComparer CreateComparer(List Date: Sun, 18 Oct 2020 09:49:20 +0300 Subject: [PATCH 2/2] fix: change return value As this is done on a machine with no formatting, I need to rely on the developer on the other end to verify the code Co-authored-by: Ilya --- .../utility/FormatAndOutput/format-wide/Format-Wide.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/FormatAndOutput/format-wide/Format-Wide.cs b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/FormatAndOutput/format-wide/Format-Wide.cs index ef4176303bd..398c08b3a2d 100644 --- a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/FormatAndOutput/format-wide/Format-Wide.cs +++ b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/FormatAndOutput/format-wide/Format-Wide.cs @@ -50,7 +50,7 @@ public SwitchParameter AutoSize get { if (_autosize.HasValue) - return _autosize; + return _autosize.GetValueOrDefault(); return false; } @@ -145,4 +145,3 @@ internal override FormattingCommandLineParameters GetCommandLineParameters() } } } -