Allow 'name' as an alias key for 'label' in ConvertTo-Html, allow the 'width' entry to be an integer (#8426)
This commit is contained in:
parent
f1218bd3d9
commit
20919ee793
2 changed files with 28 additions and 8 deletions
|
@ -326,9 +326,11 @@ namespace Microsoft.PowerShell.Commands
|
||||||
protected override void SetEntries()
|
protected override void SetEntries()
|
||||||
{
|
{
|
||||||
this.hashEntries.Add(new ExpressionEntryDefinition());
|
this.hashEntries.Add(new ExpressionEntryDefinition());
|
||||||
this.hashEntries.Add(new HashtableEntryDefinition(ConvertHTMLParameterDefinitionKeys.LabelEntryKey, new Type[] { typeof(string) }));
|
this.hashEntries.Add(new LabelEntryDefinition());
|
||||||
this.hashEntries.Add(new HashtableEntryDefinition(ConvertHTMLParameterDefinitionKeys.AlignmentEntryKey, new Type[] { typeof(string) }));
|
this.hashEntries.Add(new HashtableEntryDefinition(ConvertHTMLParameterDefinitionKeys.AlignmentEntryKey, new[] { typeof(string) }));
|
||||||
this.hashEntries.Add(new HashtableEntryDefinition(ConvertHTMLParameterDefinitionKeys.WidthEntryKey, new Type[] { typeof(string) }));
|
|
||||||
|
// Note: We accept "width" as either string or int.
|
||||||
|
this.hashEntries.Add(new HashtableEntryDefinition(ConvertHTMLParameterDefinitionKeys.WidthEntryKey, new[] { typeof(string), typeof(int) }));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -362,7 +364,11 @@ namespace Microsoft.PowerShell.Commands
|
||||||
{
|
{
|
||||||
string label = p.GetEntry(ConvertHTMLParameterDefinitionKeys.LabelEntryKey) as string;
|
string label = p.GetEntry(ConvertHTMLParameterDefinitionKeys.LabelEntryKey) as string;
|
||||||
string alignment = p.GetEntry(ConvertHTMLParameterDefinitionKeys.AlignmentEntryKey) as string;
|
string alignment = p.GetEntry(ConvertHTMLParameterDefinitionKeys.AlignmentEntryKey) as string;
|
||||||
string width = p.GetEntry(ConvertHTMLParameterDefinitionKeys.WidthEntryKey) as string;
|
|
||||||
|
// Accept the width both as a string and as an int.
|
||||||
|
string width;
|
||||||
|
int? widthNum = p.GetEntry(ConvertHTMLParameterDefinitionKeys.WidthEntryKey) as int?;
|
||||||
|
width = widthNum != null ? widthNum.Value.ToString() : p.GetEntry(ConvertHTMLParameterDefinitionKeys.WidthEntryKey) as string;
|
||||||
PSPropertyExpression ex = p.GetEntry(FormatParameterDefinitionKeys.ExpressionEntryKey) as PSPropertyExpression;
|
PSPropertyExpression ex = p.GetEntry(FormatParameterDefinitionKeys.ExpressionEntryKey) as PSPropertyExpression;
|
||||||
List<PSPropertyExpression> resolvedNames = ex.ResolveNames(_inputObject);
|
List<PSPropertyExpression> resolvedNames = ex.ResolveNames(_inputObject);
|
||||||
foreach (PSPropertyExpression resolvedName in resolvedNames)
|
foreach (PSPropertyExpression resolvedName in resolvedNames)
|
||||||
|
|
|
@ -179,5 +179,19 @@ After the object
|
||||||
$returnString | Should -Match '\b43\b'
|
$returnString | Should -Match '\b43\b'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
It "Test ConvertTo-HTML calculated property supports 'name' key as alias of 'label'" {
|
||||||
|
$returnString = ($customObject | ConvertTo-Html @{ name = 'AgeRenamed'; e = 'Age'}) -join $newLine
|
||||||
|
$returnString | Should -Match 'AgeRenamed'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
It "Test ConvertTo-HTML calculated property supports integer 'width' entry" {
|
||||||
|
$returnString = ($customObject | ConvertTo-Html @{ e = 'Age'; width = 10 }) -join $newLine
|
||||||
|
$returnString | Should -Match '\swidth\s*=\s*(["''])10\1'
|
||||||
|
}
|
||||||
|
|
||||||
|
It "Test ConvertTo-HTML calculated property supports string 'width' entry" {
|
||||||
|
$returnString = ($customObject | ConvertTo-Html @{ e = 'Age'; width = '10' }) -join $newLine
|
||||||
|
$returnString | Should -Match '\swidth\s*=\s*(["''])10\1'
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue