From 43e0e1a1c54144ae351e1541dd0965b7792d338b Mon Sep 17 00:00:00 2001 From: Ilya Date: Wed, 18 Mar 2020 18:43:01 +0500 Subject: [PATCH] Fix default formatting for deserialized MatchInfo (#11728) MatchInfo class has ToEmphasizedString() member method to color output line. In remote scenario MatchInfo class is deserialized as Deserialized.Microsoft.PowerShell.Commands.MatchInfo without the method. As result default formating in remote scenario show nothing. The fix is to directly output Line property. --- .../PowerShellCore_format_ps1xml.cs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/System.Management.Automation/FormatAndOutput/DefaultFormatters/PowerShellCore_format_ps1xml.cs b/src/System.Management.Automation/FormatAndOutput/DefaultFormatters/PowerShellCore_format_ps1xml.cs index 09cc323b9..7dd691456 100644 --- a/src/System.Management.Automation/FormatAndOutput/DefaultFormatters/PowerShellCore_format_ps1xml.cs +++ b/src/System.Management.Automation/FormatAndOutput/DefaultFormatters/PowerShellCore_format_ps1xml.cs @@ -46,6 +46,10 @@ namespace System.Management.Automation.Runspaces "Microsoft.PowerShell.Commands.MatchInfo", ViewsOf_Microsoft_PowerShell_Commands_MatchInfo()); + yield return new ExtendedTypeDefinition( + "Deserialized.Microsoft.PowerShell.Commands.MatchInfo", + ViewsOf_Deserialized_Microsoft_PowerShell_Commands_MatchInfo()); + yield return new ExtendedTypeDefinition( "System.Management.Automation.PSVariable", ViewsOf_System_Management_Automation_PSVariable()); @@ -382,6 +386,16 @@ namespace System.Management.Automation.Runspaces .EndControl()); } + private static IEnumerable ViewsOf_Deserialized_Microsoft_PowerShell_Commands_MatchInfo() + { + yield return new FormatViewDefinition("MatchInfo", + CustomControl.Create() + .StartEntry() + .AddScriptBlockExpressionBinding(@"$_.Line") + .EndEntry() + .EndControl()); + } + private static IEnumerable ViewsOf_System_Management_Automation_PSVariable() { yield return new FormatViewDefinition("Variable",