public static JToken?ToJToken(this HoconRoot hoconRoot, Func <JValue, JValue>?jValueHandler = null) { if (hoconRoot == null) { throw new ArgumentNullException(nameof(hoconRoot)); } return(hoconRoot.Value.ToJToken(jValueHandler)); }
/// <summary> /// Initializes a new instance of the <see cref="Config"/> class. /// </summary> /// <param name="root">The root node to base this configuration.</param> /// <exception cref="ArgumentNullException">"The root value cannot be null."</exception> public Config(HoconRoot root) { if (root.Value == null) { throw new ArgumentNullException("root.Value"); } Root = root.Value; Substitutions = root.Substitutions; }
/// <summary> /// Initializes a new instance of the <see cref="Config"/> class. /// </summary> /// <param name="root">The root node to base this configuration.</param> /// <exception cref="ArgumentNullException">This exception is thrown if the given <paramref name="root"/> value is undefined.</exception> public Config(HoconRoot root) { if (root.Value == null) { throw new ArgumentNullException(nameof(root), "The root value cannot be null."); } Root = root.Value; Substitutions = root.Substitutions; }
public void SelfReferenceOptionalSubstitutionInValueConcatenationShouldBeIgnored() { var hocon = "a = ${?a}foo"; HoconRoot config = null; var ex = Record.Exception(() => config = HoconParser.Parse(hocon)); Assert.Null(ex); Assert.Equal("foo", config.GetString("a")); }
public FlatConfig(HoconRoot root) : base(root) { if (root is FlatConfig caching) { _cache = caching._cache; } else { _cache = new ConcurrentDictionary <string, HoconValue>(); } }
public void OptionalSubstitutionCycleShouldBeIgnored() { var hocon = "foo : ${?foo}"; HoconRoot config = null; var ex = Record.Exception(() => config = HoconParser.Parse(hocon)); Assert.Null(ex); // should not create a field Assert.False(config.HasPath("foo")); }
public void HiddenSubstitutionShouldNeverBeEvaluated() { var hocon = @" foo : ${does-not-exist} foo : 42"; HoconRoot config = null; var ex = Record.Exception(() => config = Parser.Parse(hocon)); Assert.Null(ex); Assert.Equal(42, config.GetInt("foo")); }
public void PlusEqualOperatorShouldExpandToSelfReferencingArrayConcatenation() { var hocon = @" a = [ 1, 2 ] a += 3 a += ${b} b = [ 4, 5 ] "; HoconRoot config = null; var ex = Record.Exception(() => config = Parser.Parse(hocon)); Assert.Null(ex); Assert.True(new [] { 1, 2, 3, 4, 5 }.SequenceEqual(config.GetIntList("a"))); }
public void MergedSubstitutionShouldAlwaysResolveToOlderValue() { var hocon = @" foo : { a : { c : 1 } } foo : ${foo.a} foo : { a : 2 }"; HoconRoot config = null; var ex = Record.Exception(() => config = HoconParser.Parse(hocon)); Assert.Null(ex); Assert.Equal(2, config.GetInt("foo.a")); Assert.Equal(1, config.GetInt("foo.c")); Assert.False(config.HasPath("foo.a.c")); }
public void SubstitutionToAnotherMemberOfTheSameObjectAreResolvedNormally() { var hocon = @" bar : { foo : 42, baz : ${bar.foo} } bar : { foo : 43 }"; HoconRoot config = null; var ex = Record.Exception(() => config = HoconParser.Parse(hocon)); Assert.Null(ex); Assert.Equal(43, config.GetInt("bar.foo")); Assert.Equal(43, config.GetInt("bar.baz")); }
public void MutuallyReferringObjectsAreResolvedNormally() { var hocon = @" // bar.a should end up as 4 bar : { a : ${foo.d}, b : 1 } bar.b = 3 // foo.c should end up as 3 foo : { c : ${bar.b}, d : 2 } foo.d = 4"; HoconRoot config = null; var ex = Record.Exception(() => config = HoconParser.Parse(hocon)); Assert.Null(ex); Assert.Equal(4, config.GetInt("bar.a")); Assert.Equal(3, config.GetInt("foo.c")); }
public void PlusEqualOperatorShouldExpandToSelfReferencingArrayConcatenation() { var hocon = @" a = [ 1, 2 ] a += 3 a += ${b} b = [ 4, 5 ] "; HoconRoot config = null; var ex = Record.Exception(() => config = HoconParser.Parse(hocon)); Assert.Null(ex); var array = config.GetValue("a").GetArray(); Assert.Equal(1, array[0].GetInt()); Assert.Equal(2, array[1].GetInt()); Assert.Equal(3, array[2].GetInt()); Assert.True(new[] { 4, 5 }.SequenceEqual(array[3].GetIntList())); }
/// <summary> /// Generates a configuration defined in the supplied /// HOCON (Human-Optimized Config Object Notation) string. /// </summary> /// <param name="hocon">A string that contains configuration options to use.</param> /// <param name="includeCallback">callback used to resolve includes</param> /// <returns>The configuration defined in the supplied HOCON string.</returns> public static Config ParseString(string hocon, Func <string, HoconRoot> includeCallback) { HoconRoot res = Parser.Parse(hocon, includeCallback); return(new Config(res)); }
/// <summary> /// Parses the string. /// </summary> /// <param name="hocon">The json.</param> /// <returns>Config.</returns> public static Config ParseString(string hocon) { HoconRoot res = Parser.Parse(hocon); return(new Config(res)); }
/// <inheritdoc cref="Config()"/> /// <param name="source">The configuration to use as the primary source.</param> /// <param name="fallback">The configuration to use as a secondary source.</param> /// <exception cref="ArgumentNullException">The source configuration cannot be null.</exception> public Config(HoconRoot source, Config fallback) : base(source?.Value, source?.Substitutions ?? Enumerable.Empty <HoconSubstitution>()) { Fallback = fallback; }
public static HoconImmutableObject ToHoconImmutable(this HoconRoot root) { return(new HoconImmutableObjectBuilder() .Merge(root.Value.GetObject()) .Build()); }
public CachingConfig(HoconRoot root) : base(root) { _entryMap = new ConcurrentDictionary <string, IPathEntry>(); }
/// <inheritdoc cref="Config()"/> /// <param name="root">The root node to base this configuration.</param> /// <exception cref="T:System.ArgumentNullException">"The root value cannot be null."</exception> public Config(HoconRoot root) : base(root?.Value, root?.Substitutions ?? Enumerable.Empty <HoconSubstitution>()) { }