private static TomlTable FindOrCreateOwnerTableForTable( TomlTable current, KeyChain keys, out TomlKey last, TomlTable.TableTypes tableType = TomlTable.TableTypes.Default) { if (keys.IsLastSegment) { last = keys.Key; return(current); } TomlObject row = current.TryGetValue(keys.Key); if (row != null) { if (row is TomlTable tbl) { return(FindOrCreateOwnerTableForTable(tbl, keys.Next, out last, tableType)); } else if (row is TomlTableArray ta) { return(FindOrCreateOwnerTableForTable(ta.Last(), keys.Next, out last, tableType)); } else { throw new InvalidOperationException( $"Key '{keys}' corresponds to a TOML object hat is not of type TOML table."); } } else { TomlTable t = new TomlTable(current.Root, tableType); current.AddRow(keys.Key, t); return(FindOrCreateOwnerTableForTable(t, keys.Next, out last, tableType)); } }
public void WriteTomlTableArray(TomlKey key, TomlTableArray tableArray) { this.WritePrependComments(tableArray); const string assignment = " = [ "; this.writer.Write(key.ToString()); this.writer.Write(assignment); int indentLen = key.ToString().Length + assignment.Length; string indent = new string(' ', indentLen); for (int i = 0; i < tableArray.Items.Count; i++) { this.WriteInlineTableBody(tableArray.Items[i]); if (i < tableArray.Items.Count - 1) { this.writer.Write(","); this.writer.WriteLine(); this.writer.Write(indent); } } this.writer.WriteLine(" ]"); }
protected void WriteArray(TomlKey key, TomlArray array) { this.writer.Write(key.ToString()); this.writer.Write(" = "); this.WriteArrayPart(array); }
private void WriteTomlTable(string parentKey, TomlKey key, TomlTable table) { switch (table.TableType) { case TomlTable.TableTypes.Default: this.WriteNormalTomlTable(parentKey, key, table); break; case TomlTable.TableTypes.Inline: this.WriteTomlInlineTable(parentKey, key, table); break; } }
public TomlKey ExpressionKey() { if (this.Next.HasNode) { throw new InvalidOperationException("Cannot convert this key to a expression key."); } return(TomlKey.FromToken(this.Key.SyntaxNode().Terminal)); }
public void WriteInlineTable(TomlKey key, TomlTable table) { this.WritePrependComments(table); this.writer.Write(key.ToString()); this.writer.Write(" = "); this.WriteInlineTableBody(table); this.WriteAppendComments(table); }
private static TomlTable GetExistingOrCreateAndAddTable(TomlTable tbl, TomlKey key) { Func <TomlTable, TomlTable> createNew = (e) => { var newTable = new TomlTable(tbl.Root); tbl.AddRow(key, newTable); return(newTable); }; return(GetExistinOrCreateAndAdd(tbl, key, createNew)); }
private static TomlTable GetExistinOrCreateAndAdd(TomlTable tbl, TomlKey key, Func <TomlTable, TomlTable> createNewItem) { var existingTargetTable = TryGetTableEntry(tbl.TryGetValue(key)); if (existingTargetTable != null) { return(existingTargetTable); } return(createNewItem(tbl)); }
private void WriteNormalTomlTable(string parentKey, TomlKey key, TomlTable table) { this.WritePrependComments(table); this.writer.Write('['); this.writer.Write(parentKey + key); this.writer.Write(']'); this.writer.WriteLine(); this.WriteAppendComments(table); foreach (var r in table.InternalRows) { this.WriteTableRow(CombineKey(parentKey, key), r); } }
public static SerializationInfo CreateFromMemberInfo(MemberInfo mi, TomlKey key) { if (mi is PropertyInfo pi) { return(new SerializationInfo(pi, key)); } else if (mi is FieldInfo fi) { return(new SerializationInfo(fi, key)); } else { throw new ArgumentException($"Cannot create serialization info from unsupported member info type '{mi.GetType()}'."); } }
protected void WriteArray(TomlKey key, TomlArray array) { this.writer.Write(key.ToString()); this.writer.Write(" = ["); for (int i = 0; i < array.Items.Length - 1; i++) { this.WriteValue(array[i]); this.writer.Write(", "); } if (array.Items.Length > 0) { this.WriteValue(array.Items[array.Items.Length - 1]); } this.writer.Write(']'); }
private void WriteTomlTableArray(string parentKey, TomlKey key, TomlTableArray tableArray) { if (IsInlineTomlTableArray(tableArray)) { var inlineWriter = new TomlInlineTableWriter(this.writer, this.settings); inlineWriter.WriteTomlTableArray(key, tableArray); } else { this.WritePrependComments(tableArray); foreach (var t in tableArray.Items) { this.writer.Write("[["); this.writer.Write(parentKey + key.ToString()); this.writer.Write("]]"); this.writer.WriteLine(); this.WriteAppendComments(tableArray); this.WriteTableRows(CombineKey(parentKey, key), t); } } }
private static TomlTableArray GetExistingOrCreateAndAdd(TomlTable target, TomlKey key, Token errorPosition) { TomlObject existing = target.TryGetValue(key); var typed = existing as TomlTableArray; if (existing != null && typed == null) { throw Parser.CreateParseError( errorPosition, $"Cannot create array of tables with key '{key}' because there already is an row with that key of type '{existing.ReadableTypeName}'."); } else if (typed != null) { return(typed); } var newTableArray = new TomlTableArray(target.Root); target.AddRow(key, newTableArray); return(newTableArray); }
public SerializationInfo(FieldInfo fi, TomlKey key) { this.Member = new SerializationMember(fi); this.Key = key; }
public SerializationInfo(PropertyInfo pi, TomlKey key) { this.Member = new SerializationMember(pi); this.Key = key; }
private void WriteTomlArrayWithComments(TomlKey key, TomlArray array) { this.WritePrependComments(array); this.WriteArray(key, array); this.WriteAppendComments(array); }
private void WriteTomlInlineTable(string parentKey, TomlKey key, TomlTable table) { var inlineWriter = new TomlInlineTableWriter(this.writer, this.settings); inlineWriter.WriteInlineTable(key, table); }
private void WriteTomlDottedTable(TomlKey key, TomlTable table) { var dottedWriter = new DottedTableWriter(this.writer, this.settings); dottedWriter.WriteDottedTable(table, key); }
public SerializationInfo(SerializationMember si, TomlKey key) { this.Member = si; this.Key = key; }
private static string CombineKey(string parent, TomlKey key) => parent + key.ToString() + ".";