11using System ;
22using System . Collections . Generic ;
33using System . Linq ;
4- using Octopus . CoreUtilities . Extensions ;
54using Sprache ;
65
76namespace 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