public static TomlTable TransformToSourceTable(this TomlTable table, IConfigSource source, TomlObject rootSource = null) { table.CheckNotNull(nameof(table)); var sourcesTable = rootSource == null ? Toml.Create(table.TableType) : TomlObjectFactory.CreateEmptyAttachedTable(rootSource, table.TableType); foreach (var r in table.Rows) { if (r.Value.TomlType == TomlObjectType.Table) { sourcesTable[r.Key] = ((TomlTable)r.Value).TransformToSourceTable(source, sourcesTable); } else if (r.Value.TomlType == TomlObjectType.ArrayOfTables) { var arr = (TomlTableArray)r.Value; var sourcesArray = new TomlTableArray(table.Root, arr.Items.Select(t => t.TransformToSourceTable(source, sourcesTable))); sourcesTable[r.Key] = sourcesArray; } else { sourcesTable[r.Key] = new TomlSource(sourcesTable.Root, source); } } return(sourcesTable); }
static CombineTablesTests() { X = Toml.Create(); X.Add(XKey, XVal); X.Add(SameKey, XVal); var xs = X.Add(SubTableKey, TomlObjectFactory.CreateEmptyAttachedTable(X)).Added; xs.Add(SubTableValueKey, XSubTableVal); Y = Toml.Create(); Y.Add(YKey, YVal); Y.Add(SameKey, YVal); var ys = Y.Add(SubTableKey, X.CreateEmptyAttachedTable()).Added; ys.Add(SubTableValueKey, YSubTableVal); Dx = Toml.Create(); Dx.Add("a", (long)1); Dx.Add("c", (long)3).ConfigureAdded(c => c.AddComment("xcc")); Dy = Toml.Create(); Dy.Add("b", (long)2).ConfigureAdded(c => c.AddComment("ybc")); Dy.Add("c", (long)4).ConfigureAdded(c => c.AddComment("ycc")); }