From 25e09ac0a8cab0d775197bb21d5a69c60068778b Mon Sep 17 00:00:00 2001 From: michaelongso Date: Tue, 8 Nov 2022 11:10:31 +1100 Subject: [PATCH] Removed Octopus.CoreUtilities reference. --- .../Octopus.CoreParsers.Hcl.csproj | 1 - .../Octopus/CoreParsers/Hcl/HclElement.cs | 14 +++++++++----- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/source/Octopus.Core.Parsers.Hcl/Octopus.CoreParsers.Hcl.csproj b/source/Octopus.Core.Parsers.Hcl/Octopus.CoreParsers.Hcl.csproj index 030127b..75eb891 100644 --- a/source/Octopus.Core.Parsers.Hcl/Octopus.CoreParsers.Hcl.csproj +++ b/source/Octopus.Core.Parsers.Hcl/Octopus.CoreParsers.Hcl.csproj @@ -20,7 +20,6 @@ - diff --git a/source/Octopus.Core.Parsers.Hcl/Octopus/CoreParsers/Hcl/HclElement.cs b/source/Octopus.Core.Parsers.Hcl/Octopus/CoreParsers/Hcl/HclElement.cs index 55a791e..4989cff 100644 --- a/source/Octopus.Core.Parsers.Hcl/Octopus/CoreParsers/Hcl/HclElement.cs +++ b/source/Octopus.Core.Parsers.Hcl/Octopus/CoreParsers/Hcl/HclElement.cs @@ -1,7 +1,6 @@ using System; using System.Collections.Generic; using System.Linq; -using Octopus.CoreUtilities.Extensions; using Sprache; namespace Octopus.CoreParsers.Hcl @@ -163,7 +162,7 @@ public virtual string OriginalName public virtual HclElement Child { get => Children?.FirstOrDefault(); - set => Children = value?.ToEnumerable(); + set => Children = value is not null ? new[] { value } : null; } /// @@ -186,8 +185,8 @@ public virtual string ToString(bool naked, int indent) var separator = indent == -1 ? ", " : "\n"; return indentString + OriginalName + - ProcessedValue?.Map(a => " \"" + EscapeQuotes(a) + "\"") + - Type?.Map(a => " \"" + EscapeQuotes(a) + "\"") + + RunIfNotNull(ProcessedValue, a => " \"" + EscapeQuotes(a) + "\"") + + RunIfNotNull(Type, a => " \"" + EscapeQuotes(a) + "\"") + " {" + lineBreak + string.Join(separator, Children?.Select(child => child.ToString(nextIndent)) ?? Enumerable.Empty()) + @@ -254,11 +253,16 @@ public override int GetHashCode() return hash; } - protected string EscapeQuotes(string input) + protected static string EscapeQuotes(string input) { if (input == null) throw new ArgumentException("input can not be null"); return HclParser.StringLiteralQuoteContentReverse.Parse(input); } + + private static TResult RunIfNotNull(TSource input, Func command) + { + return input is null ? default : command(input); + } } } \ No newline at end of file