コード例 #1
0
        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));
        }
コード例 #2
0
ファイル: Config.cs プロジェクト: anthrax3/hocon
        /// <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;
        }
コード例 #3
0
ファイル: Config.cs プロジェクト: yyp2003net/akka.net
        /// <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;
        }
コード例 #4
0
        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"));
        }
コード例 #5
0
 public FlatConfig(HoconRoot root) : base(root)
 {
     if (root is FlatConfig caching)
     {
         _cache = caching._cache;
     }
     else
     {
         _cache = new ConcurrentDictionary <string, HoconValue>();
     }
 }
コード例 #6
0
        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"));
        }
コード例 #7
0
        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"));
        }
コード例 #8
0
        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")));
        }
コード例 #9
0
        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"));
        }
コード例 #10
0
        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"));
        }
コード例 #11
0
        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"));
        }
コード例 #12
0
        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()));
        }
コード例 #13
0
ファイル: ConfigurationFactory.cs プロジェクト: ziez/akka.net
        /// <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));
        }
コード例 #14
0
        /// <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));
        }
コード例 #15
0
ファイル: Config.cs プロジェクト: lulzzz/SharpServer
 /// <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;
 }
コード例 #16
0
 public static HoconImmutableObject ToHoconImmutable(this HoconRoot root)
 {
     return(new HoconImmutableObjectBuilder()
            .Merge(root.Value.GetObject())
            .Build());
 }
コード例 #17
0
 public CachingConfig(HoconRoot root) : base(root)
 {
     _entryMap = new ConcurrentDictionary <string, IPathEntry>();
 }
コード例 #18
0
ファイル: Config.cs プロジェクト: lulzzz/SharpServer
 /// <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>())
 {
 }