예제 #1
0
        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));
            }
        }
예제 #2
0
            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(" ]");
            }
예제 #3
0
        protected void WriteArray(TomlKey key, TomlArray array)
        {
            this.writer.Write(key.ToString());
            this.writer.Write(" = ");

            this.WriteArrayPart(array);
        }
예제 #4
0
        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;
            }
        }
예제 #5
0
        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));
        }
예제 #6
0
            public void WriteInlineTable(TomlKey key, TomlTable table)
            {
                this.WritePrependComments(table);

                this.writer.Write(key.ToString());
                this.writer.Write(" = ");
                this.WriteInlineTableBody(table);

                this.WriteAppendComments(table);
            }
예제 #7
0
        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));
        }
예제 #8
0
        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));
        }
예제 #9
0
        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);
            }
        }
예제 #10
0
 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()}'.");
     }
 }
예제 #11
0
        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(']');
        }
예제 #12
0
        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);
                }
            }
        }
예제 #13
0
        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);
        }
예제 #14
0
 public SerializationInfo(FieldInfo fi, TomlKey key)
 {
     this.Member = new SerializationMember(fi);
     this.Key    = key;
 }
예제 #15
0
 public SerializationInfo(PropertyInfo pi, TomlKey key)
 {
     this.Member = new SerializationMember(pi);
     this.Key    = key;
 }
예제 #16
0
 private void WriteTomlArrayWithComments(TomlKey key, TomlArray array)
 {
     this.WritePrependComments(array);
     this.WriteArray(key, array);
     this.WriteAppendComments(array);
 }
예제 #17
0
        private void WriteTomlInlineTable(string parentKey, TomlKey key, TomlTable table)
        {
            var inlineWriter = new TomlInlineTableWriter(this.writer, this.settings);

            inlineWriter.WriteInlineTable(key, table);
        }
예제 #18
0
        private void WriteTomlDottedTable(TomlKey key, TomlTable table)
        {
            var dottedWriter = new DottedTableWriter(this.writer, this.settings);

            dottedWriter.WriteDottedTable(table, key);
        }
예제 #19
0
 public SerializationInfo(SerializationMember si, TomlKey key)
 {
     this.Member = si;
     this.Key    = key;
 }
예제 #20
0
 private static string CombineKey(string parent, TomlKey key) => parent + key.ToString() + ".";