mirror of
https://github.com/PowerShell/PowerShell
synced 2026-06-08 12:12:50 +00:00
Use bool?.GetValueOrDefault() in FormatWideCommand (#15988)
This commit is contained in:
committed by
Aditya Patwardhan
parent
b9ca321bd4
commit
0c984f2141
+14
-35
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user