@@ -158,7 +158,7 @@ public string GetString(string path, string @default = null)
158
158
public string GetString ( HoconPath path , string @default = null )
159
159
{
160
160
var value = GetNode ( path ) ;
161
- return ReferenceEquals ( value , HoconValue . Undefined ) ? @default : value . GetString ( ) ;
161
+ return value == null ? @default : value . GetString ( ) ;
162
162
}
163
163
164
164
/// <summary>
@@ -173,11 +173,8 @@ public bool GetBoolean(string path, bool @default = false)
173
173
/// <inheritdoc cref="GetBoolean(string,bool)"/>
174
174
public bool GetBoolean ( HoconPath path , bool @default = false )
175
175
{
176
- HoconValue value = GetNode ( path ) ;
177
- if ( ReferenceEquals ( value , HoconValue . Undefined ) )
178
- return @default ;
179
-
180
- return value . GetBoolean ( ) ;
176
+ var value = GetNode ( path ) ;
177
+ return value == null ? @default : value . GetBoolean ( ) ;
181
178
}
182
179
183
180
/// <summary>
@@ -191,10 +188,8 @@ public bool GetBoolean(HoconPath path, bool @default = false)
191
188
/// <inheritdoc cref="GetByteSize(string)"/>
192
189
public long ? GetByteSize ( HoconPath path )
193
190
{
194
- HoconValue value = GetNode ( path ) ;
195
- if ( ReferenceEquals ( value , HoconValue . Undefined ) )
196
- return null ;
197
- return value . GetByteSize ( ) ;
191
+ var value = GetNode ( path ) ;
192
+ return value ? . GetByteSize ( ) ;
198
193
}
199
194
200
195
/// <summary>
@@ -209,11 +204,8 @@ public int GetInt(string path, int @default = 0)
209
204
/// <inheritdoc cref="GetInt(string,int)"/>
210
205
public int GetInt ( HoconPath path , int @default = 0 )
211
206
{
212
- HoconValue value = GetNode ( path ) ;
213
- if ( ReferenceEquals ( value , HoconValue . Undefined ) )
214
- return @default ;
215
-
216
- return value . GetInt ( ) ;
207
+ var value = GetNode ( path ) ;
208
+ return value == null ? @default : value . GetInt ( ) ;
217
209
}
218
210
219
211
/// <summary>
@@ -228,23 +220,17 @@ public long GetLong(string path, long @default = 0)
228
220
/// <inheritdoc cref="GetLong(string,long)"/>
229
221
public long GetLong ( HoconPath path , long @default = 0 )
230
222
{
231
- HoconValue value = GetNode ( path ) ;
232
- if ( ReferenceEquals ( value , HoconValue . Undefined ) )
233
- return @default ;
234
-
235
- return value . GetLong ( ) ;
223
+ var value = GetNode ( path ) ;
224
+ return value == null ? @default : value . GetLong ( ) ;
236
225
}
237
226
238
227
public byte GetByte ( string path , byte @default = 0 )
239
228
=> GetByte ( HoconPath . Parse ( path ) , @default ) ;
240
229
241
230
public byte GetByte ( HoconPath path , byte @default = 0 )
242
231
{
243
- HoconValue value = GetNode ( path ) ;
244
- if ( ReferenceEquals ( value , HoconValue . Undefined ) )
245
- return @default ;
246
-
247
- return value . GetByte ( ) ;
232
+ var value = GetNode ( path ) ;
233
+ return value == null ? @default : value . GetByte ( ) ;
248
234
}
249
235
250
236
/// <summary>
@@ -259,11 +245,8 @@ public float GetFloat(string path, float @default = 0)
259
245
/// <inheritdoc cref="GetFloat(string,float)"/>
260
246
public float GetFloat ( HoconPath path , float @default = 0 )
261
247
{
262
- HoconValue value = GetNode ( path ) ;
263
- if ( ReferenceEquals ( value , HoconValue . Undefined ) )
264
- return @default ;
265
-
266
- return value . GetFloat ( ) ;
248
+ var value = GetNode ( path ) ;
249
+ return value == null ? @default : value . GetFloat ( ) ;
267
250
}
268
251
269
252
/// <summary>
@@ -278,11 +261,8 @@ public decimal GetDecimal(string path, decimal @default = 0)
278
261
/// <inheritdoc cref="GetDecimal(string,decimal)"/>
279
262
public decimal GetDecimal ( HoconPath path , decimal @default = 0 )
280
263
{
281
- HoconValue value = GetNode ( path ) ;
282
- if ( ReferenceEquals ( value , HoconValue . Undefined ) )
283
- return @default ;
284
-
285
- return value . GetDecimal ( ) ;
264
+ var value = GetNode ( path ) ;
265
+ return value == null ? @default : value . GetDecimal ( ) ;
286
266
}
287
267
288
268
/// <summary>
@@ -297,11 +277,8 @@ public double GetDouble(string path, double @default = 0)
297
277
/// <inheritdoc cref="GetDouble(string,double)"/>
298
278
public double GetDouble ( HoconPath path , double @default = 0 )
299
279
{
300
- HoconValue value = GetNode ( path ) ;
301
- if ( ReferenceEquals ( value , HoconValue . Undefined ) )
302
- return @default ;
303
-
304
- return value . GetDouble ( ) ;
280
+ var value = GetNode ( path ) ;
281
+ return value == null ? @default : value . GetDouble ( ) ;
305
282
}
306
283
307
284
/// <summary>
@@ -316,11 +293,8 @@ public HoconObject GetObject(string path, HoconObject @default = null)
316
293
/// <inheritdoc cref="GetObject(string,HoconObject)"/>
317
294
public HoconObject GetObject ( HoconPath path , HoconObject @default = null )
318
295
{
319
- HoconValue value = GetNode ( path ) ;
320
- if ( ReferenceEquals ( value , HoconValue . Undefined ) )
321
- return @default ;
322
-
323
- return value . GetObject ( ) ;
296
+ var value = GetNode ( path ) ;
297
+ return value == null ? @default : value . GetObject ( ) ;
324
298
}
325
299
326
300
@@ -335,9 +309,9 @@ public IList<Boolean> GetBooleanList(string path)
335
309
/// <inheritdoc cref="GetBooleanList(string)"/>
336
310
public IList < Boolean > GetBooleanList ( HoconPath path )
337
311
{
338
- HoconValue value = GetNode ( path ) ;
339
- if ( ReferenceEquals ( value , HoconValue . Undefined ) )
340
- throw new HoconParserException ( $ "Hocon path { path } was not an array or a numerically-indexed object .") ;
312
+ var value = GetNode ( path ) ;
313
+ if ( value == null )
314
+ throw new HoconParserException ( $ "Hocon path { path } does not exist .") ;
341
315
342
316
return value . GetBooleanList ( ) ;
343
317
}
@@ -353,9 +327,9 @@ public IList<decimal> GetDecimalList(string path)
353
327
/// <inheritdoc cref="GetDecimalList(string)"/>
354
328
public IList < decimal > GetDecimalList ( HoconPath path )
355
329
{
356
- HoconValue value = GetNode ( path ) ;
357
- if ( ReferenceEquals ( value , HoconValue . Undefined ) )
358
- throw new HoconParserException ( $ "Hocon path { path } was not an array or a numerically-indexed object .") ;
330
+ var value = GetNode ( path ) ;
331
+ if ( value == null )
332
+ throw new HoconParserException ( $ "Hocon path { path } does not exist .") ;
359
333
360
334
return value . GetDecimalList ( ) ;
361
335
}
@@ -371,9 +345,9 @@ public IList<float> GetFloatList(string path)
371
345
/// <inheritdoc cref="GetFloatList(string)"/>
372
346
public IList < float > GetFloatList ( HoconPath path )
373
347
{
374
- HoconValue value = GetNode ( path ) ;
375
- if ( ReferenceEquals ( value , HoconValue . Undefined ) )
376
- throw new HoconParserException ( $ "Hocon path { path } was not an array or a numerically-indexed object .") ;
348
+ var value = GetNode ( path ) ;
349
+ if ( value == null )
350
+ throw new HoconParserException ( $ "Hocon path { path } does not exist .") ;
377
351
378
352
return value . GetFloatList ( ) ;
379
353
}
@@ -389,9 +363,9 @@ public IList<double> GetDoubleList(string path)
389
363
/// <inheritdoc cref="GetDoubleList(string)"/>
390
364
public IList < double > GetDoubleList ( HoconPath path )
391
365
{
392
- HoconValue value = GetNode ( path ) ;
393
- if ( ReferenceEquals ( value , HoconValue . Undefined ) )
394
- throw new HoconParserException ( $ "Hocon path { path } was not an array or a numerically-indexed object .") ;
366
+ var value = GetNode ( path ) ;
367
+ if ( value == null )
368
+ throw new HoconParserException ( $ "Hocon path { path } does not exist .") ;
395
369
396
370
return value . GetDoubleList ( ) ;
397
371
}
@@ -407,9 +381,9 @@ public IList<int> GetIntList(string path)
407
381
/// <inheritdoc cref="GetIntList(string)"/>
408
382
public IList < int > GetIntList ( HoconPath path )
409
383
{
410
- HoconValue value = GetNode ( path ) ;
411
- if ( ReferenceEquals ( value , HoconValue . Undefined ) )
412
- throw new HoconParserException ( $ "Hocon path { path } was not an array or a numerically-indexed object .") ;
384
+ var value = GetNode ( path ) ;
385
+ if ( value == null )
386
+ throw new HoconParserException ( $ "Hocon path { path } does not exist .") ;
413
387
414
388
return value . GetIntList ( ) ;
415
389
}
@@ -425,9 +399,9 @@ public IList<long> GetLongList(string path)
425
399
/// <inheritdoc cref="GetLongList(string)"/>
426
400
public IList < long > GetLongList ( HoconPath path )
427
401
{
428
- HoconValue value = GetNode ( path ) ;
429
- if ( ReferenceEquals ( value , HoconValue . Undefined ) )
430
- throw new HoconParserException ( $ "Hocon path { path } was not an array or a numerically-indexed object .") ;
402
+ var value = GetNode ( path ) ;
403
+ if ( value == null )
404
+ throw new HoconParserException ( $ "Hocon path { path } does not exist .") ;
431
405
432
406
return value . GetLongList ( ) ;
433
407
}
@@ -443,9 +417,9 @@ public IList<byte> GetByteList(string path)
443
417
/// <inheritdoc cref="GetByteList(string)"/>
444
418
public IList < byte > GetByteList ( HoconPath path )
445
419
{
446
- HoconValue value = GetNode ( path ) ;
447
- if ( ReferenceEquals ( value , HoconValue . Undefined ) )
448
- throw new HoconParserException ( $ "Hocon path { path } was not an array or a numerically-indexed object .") ;
420
+ var value = GetNode ( path ) ;
421
+ if ( value == null )
422
+ throw new HoconParserException ( $ "Hocon path { path } does not exist .") ;
449
423
450
424
return value . GetByteList ( ) ;
451
425
}
@@ -461,9 +435,9 @@ public IList<string> GetStringList(string path)
461
435
/// <inheritdoc cref="GetStringList(string)"/>
462
436
public IList < string > GetStringList ( HoconPath path )
463
437
{
464
- HoconValue value = GetNode ( path ) ;
465
- if ( ReferenceEquals ( value , HoconValue . Undefined ) )
466
- throw new HoconParserException ( $ "Hocon path { path } was not an array or a numerically-indexed object .") ;
438
+ var value = GetNode ( path ) ;
439
+ if ( value == null )
440
+ throw new HoconParserException ( $ "Hocon path { path } does not exist .") ;
467
441
468
442
return value . GetStringList ( ) ;
469
443
}
@@ -479,9 +453,8 @@ public IList<HoconObject> GetObjectList(string path)
479
453
public IList < HoconObject > GetObjectList ( HoconPath path )
480
454
{
481
455
var value = GetNode ( path ) ;
482
-
483
- if ( ReferenceEquals ( value , HoconValue . Undefined ) )
484
- throw new HoconParserException ( $ "Hocon path { path } was not an array or a numerically-indexed object.") ;
456
+ if ( value == null )
457
+ throw new HoconParserException ( $ "Hocon path { path } does not exist.") ;
485
458
486
459
return value . GetObjectList ( ) ;
487
460
}
@@ -497,7 +470,7 @@ public HoconValue GetValue(string path)
497
470
/// <inheritdoc cref="GetValue(string)"/>
498
471
public HoconValue GetValue ( HoconPath path )
499
472
{
500
- HoconValue value = GetNode ( path ) ;
473
+ var value = GetNode ( path ) ;
501
474
return value ;
502
475
}
503
476
@@ -524,11 +497,8 @@ public TimeSpan GetTimeSpan(string path, TimeSpan? @default = null, bool allowIn
524
497
/// <inheritdoc cref="GetTimeSpan(string,System.Nullable{System.TimeSpan},bool)"/>
525
498
public TimeSpan GetTimeSpan ( HoconPath path , TimeSpan ? @default = null , bool allowInfinite = true )
526
499
{
527
- HoconValue value = GetNode ( path ) ;
528
- if ( value == null )
529
- return @default . GetValueOrDefault ( ) ;
530
-
531
- return value . GetTimeSpan ( allowInfinite ) ;
500
+ var value = GetNode ( path ) ;
501
+ return value == null ? @default . GetValueOrDefault ( ) : value . GetTimeSpan ( allowInfinite ) ;
532
502
}
533
503
#endregion
534
504
0 commit comments