private static void ParseObject( HoconValue owner, string currentPath, IConfiguration conf) { if (!owner.IsObject()) { owner.NewValue(new HoconObject()); } HoconObject hoconObject = owner.GetObject(); foreach (var section in conf.GetChildren()) { if (int.TryParse(section.Key, out _)) { if (!owner.Values[0].IsArray()) { owner.Clear(); owner.NewValue(new HoconArray()); } var array = (HoconArray)owner.Values[0]; var value = new HoconValue(); ParseSection(currentPath, section, value); array.Add(value); } else { ParseSection(currentPath, section, hoconObject.GetOrCreateKey(section.Key)); } } }
public HoconImmutableObjectBuilder Merge(HoconObject @object) { foreach (var kvp in @object) { this[kvp.Key] = kvp.Value.ToHoconImmutable(); } return(this); }
private void VisitHoconObject(HoconObject hObject) { foreach (var field in hObject) { EnterContext(field.Key); VisitHoconField(field.Value); ExitContext(); } }
private void VisitHoconObject(string path, HoconObject o) { if (o == null) { return; } foreach (var value in o.Items) { VisitHoconValue(PathCombine(path, value.Key), value.Value); } }
private void ParseObject(HoconValue owner, bool root, string currentPath) { if (!owner.IsObject()) { owner.NewValue(new HoconObject()); } HoconObject currentObject = owner.GetObject(); while (!_reader.EoF) { Token t = _reader.PullNext(); switch (t.Kind) { case TokenKind.Include: if (_includeCallback == null) { throw new InvalidOperationException("include callback is null"); } var included = _includeCallback(t.Value); var substitutions = included.Substitutions; foreach (var substitution in substitutions) { substitution.Path = currentPath + "." + substitution.Path; } this.substitutions.AddRange(substitutions); var otherObj = included.Value.GetObject(); owner.GetObject().Merge(otherObj); break; case TokenKind.EoF: break; case TokenKind.Key: HoconValue value = currentObject.GetOrCreateKey(t.Value); var nextPath = currentPath == "" ? t.Value : currentPath + "." + t.Value; ParseKeyContent(value, nextPath); if (!root) { return; } break; case TokenKind.ObjectEnd: return; } } }
public static JObject ToJObject(this HoconObject hoconObject, Func <JValue, JValue>?jValueHandler = null) { if (hoconObject == null) { throw new ArgumentNullException(nameof(hoconObject)); } var jObject = new JObject(); foreach (var hoconField in hoconObject) { var key = hoconField.Key; var value = hoconField.Value.Value.ToJToken(jValueHandler); if (value != null) { jObject.Add(key, value); } } return(jObject); }
public static HoconImmutableObject ToHoconImmutable(this HoconObject @object) { return(new HoconImmutableObjectBuilder() .Merge(@object) .Build()); }