Use bool?.GetValueOrDefault()
in FormatWideCommand
(#15988)
This commit is contained in:
parent
e3d8353e3c
commit
fa50e4dcae
|
@ -47,17 +47,8 @@ namespace Microsoft.PowerShell.Commands
|
|||
[Parameter]
|
||||
public SwitchParameter AutoSize
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_autosize.HasValue)
|
||||
return _autosize.Value;
|
||||
return false;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
_autosize = value;
|
||||
}
|
||||
get => _autosize.GetValueOrDefault();
|
||||
set => _autosize = value;
|
||||
}
|
||||
|
||||
private bool? _autosize = null;
|
||||
|
@ -70,17 +61,8 @@ namespace Microsoft.PowerShell.Commands
|
|||
[ValidateRangeAttribute(1, int.MaxValue)]
|
||||
public int Column
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_column.HasValue)
|
||||
return _column.Value;
|
||||
return -1;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
_column = value;
|
||||
}
|
||||
get => _column.GetValueOrDefault(-1);
|
||||
set => _column = value;
|
||||
}
|
||||
|
||||
private int? _column = null;
|
||||
|
@ -110,22 +92,19 @@ namespace Microsoft.PowerShell.Commands
|
|||
}
|
||||
|
||||
// we cannot specify -column and -autosize, they are mutually exclusive
|
||||
if (_autosize.HasValue && _column.HasValue)
|
||||
if (AutoSize && _column.HasValue)
|
||||
{
|
||||
if (_autosize.Value)
|
||||
{
|
||||
// the user specified -autosize:true AND a column number
|
||||
string msg = StringUtil.Format(FormatAndOut_format_xxx.CannotSpecifyAutosizeAndColumnsError);
|
||||
// the user specified -autosize:true AND a column number
|
||||
string msg = StringUtil.Format(FormatAndOut_format_xxx.CannotSpecifyAutosizeAndColumnsError);
|
||||
|
||||
ErrorRecord errorRecord = new(
|
||||
new InvalidDataException(),
|
||||
"FormatCannotSpecifyAutosizeAndColumns",
|
||||
ErrorCategory.InvalidArgument,
|
||||
null);
|
||||
ErrorRecord errorRecord = new(
|
||||
new InvalidDataException(),
|
||||
"FormatCannotSpecifyAutosizeAndColumns",
|
||||
ErrorCategory.InvalidArgument,
|
||||
null);
|
||||
|
||||
errorRecord.ErrorDetails = new ErrorDetails(msg);
|
||||
this.ThrowTerminatingError(errorRecord);
|
||||
}
|
||||
errorRecord.ErrorDetails = new ErrorDetails(msg);
|
||||
this.ThrowTerminatingError(errorRecord);
|
||||
}
|
||||
|
||||
parameters.groupByParameter = this.ProcessGroupByParameter();
|
||||
|
|
Loading…
Reference in a new issue