Skip to content

Commit 83bda77

Browse files
authored
Merge pull request #12 from OctopusDeploy/core/core-utilities-ref-removal
Removed Octopus.CoreUtilities reference
2 parents 35df8a2 + 25e09ac commit 83bda77

File tree

2 files changed

+9
-6
lines changed

2 files changed

+9
-6
lines changed

source/Octopus.Core.Parsers.Hcl/Octopus.CoreParsers.Hcl.csproj

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
</PropertyGroup>
2121

2222
<ItemGroup>
23-
<PackageReference Include="Octopus.CoreUtilities" Version="1.1.2" />
2423
<PackageReference Include="Sprache" Version="2.3.1" />
2524
</ItemGroup>
2625

source/Octopus.Core.Parsers.Hcl/Octopus/CoreParsers/Hcl/HclElement.cs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
using System;
22
using System.Collections.Generic;
33
using System.Linq;
4-
using Octopus.CoreUtilities.Extensions;
54
using Sprache;
65

76
namespace Octopus.CoreParsers.Hcl
@@ -163,7 +162,7 @@ public virtual string OriginalName
163162
public virtual HclElement Child
164163
{
165164
get => Children?.FirstOrDefault();
166-
set => Children = value?.ToEnumerable();
165+
set => Children = value is not null ? new[] { value } : null;
167166
}
168167

169168
/// <summary>
@@ -186,8 +185,8 @@ public virtual string ToString(bool naked, int indent)
186185
var separator = indent == -1 ? ", " : "\n";
187186

188187
return indentString + OriginalName +
189-
ProcessedValue?.Map(a => " \"" + EscapeQuotes(a) + "\"") +
190-
Type?.Map(a => " \"" + EscapeQuotes(a) + "\"") +
188+
RunIfNotNull(ProcessedValue, a => " \"" + EscapeQuotes(a) + "\"") +
189+
RunIfNotNull(Type, a => " \"" + EscapeQuotes(a) + "\"") +
191190
" {" + lineBreak +
192191
string.Join(separator,
193192
Children?.Select(child => child.ToString(nextIndent)) ?? Enumerable.Empty<string>()) +
@@ -254,11 +253,16 @@ public override int GetHashCode()
254253
return hash;
255254
}
256255

257-
protected string EscapeQuotes(string input)
256+
protected static string EscapeQuotes(string input)
258257
{
259258
if (input == null) throw new ArgumentException("input can not be null");
260259

261260
return HclParser.StringLiteralQuoteContentReverse.Parse(input);
262261
}
262+
263+
private static TResult RunIfNotNull<TSource, TResult>(TSource input, Func<TSource, TResult> command)
264+
{
265+
return input is null ? default : command(input);
266+
}
263267
}
264268
}

0 commit comments

Comments
 (0)