From 038786d6ab6afe2e16a17de16e5ef3ae6a1ec7cc Mon Sep 17 00:00:00 2001 From: dee-see Date: Sat, 14 Oct 2017 17:21:44 -0400 Subject: [PATCH] Fix MatchInfoContext clone implementation The old implementation always set the new object's properties to null --- .../commands/utility/MatchString.cs | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/MatchString.cs b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/MatchString.cs index 88fac123a4a..deaa37323db 100644 --- a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/MatchString.cs +++ b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/MatchString.cs @@ -61,12 +61,13 @@ internal MatchInfoContext() /// public object Clone() { - MatchInfoContext clone = new MatchInfoContext(); - clone.PreContext = (clone.PreContext != null) ? (string[])PreContext.Clone() : null; - clone.PostContext = (clone.PostContext != null) ? (string[])PostContext.Clone() : null; - clone.DisplayPreContext = (clone.DisplayPreContext != null) ? (string[])DisplayPreContext.Clone() : null; - clone.DisplayPostContext = (clone.DisplayPostContext != null) ? (string[])DisplayPostContext.Clone() : null; - return clone; + return new MatchInfoContext() + { + PreContext = (string[])PreContext?.Clone(), + PostContext = (string[])PostContext?.Clone(), + DisplayPreContext = (string[])DisplayPreContext?.Clone(), + DisplayPostContext = (string[])DisplayPostContext?.Clone() + }; } }