Esempio n. 1
0
        internal static TomlTable CreateFromComplexObject <T>(ITomlRoot root, T obj, TableTypes tableType)
        {
            if (root == null)
            {
                throw new ArgumentNullException(nameof(root));
            }
            if (obj == null)
            {
                throw new ArgumentNullException(nameof(obj));
            }

            TomlTable tt = new TomlTable(root, tableType);

            var props      = root.Settings.GetSerializationProperties(obj.GetType());
            var allObjects = new List <Tuple <string, TomlObject> >();

            foreach (var p in props)
            {
                object val = p.GetValue(obj, null);
                if (val != null)
                {
                    TomlObject to = TomlObject.CreateFrom(root, val, p);
                    AddComments(to, p);
                    tt.AddRow(new TomlKey(p.Name), to);
                }
            }

            return(tt);
        }
Esempio n. 2
0
        public static TomlFloat AddValue(this TomlTable table, string key, double value)
        {
            var f = table.CreateAttachedValue(value);

            table.AddRow(new TomlKey(key), f);
            return(f);
        }
Esempio n. 3
0
        public static TomlInt AddValue(this TomlTable table, string key, long value)
        {
            var i = table.CreateAttachedValue(value);

            table.AddRow(new TomlKey(key), i);
            return(i);
        }
Esempio n. 4
0
        public static TomlString AddValue(this TomlTable table, string key, string value)
        {
            var s = table.CreateAttachedValue(value);

            table.AddRow(new TomlKey(key), table.CreateAttachedValue(value));
            return(s);
        }
Esempio n. 5
0
        public static TomlDateTime AddValue(this TomlTable table, string key, DateTimeOffset dateTime)
        {
            var dt = table.CreateAttachedValue(dateTime);

            table.AddRow(new TomlKey(key), dt);
            return(dt);
        }
Esempio n. 6
0
        public static TomlBool AddValue(this TomlTable table, string key, bool value)
        {
            var b = table.CreateAttachedValue(value);

            table.AddRow(new TomlKey(key), b);
            return(b);
        }
Esempio n. 7
0
        public static TomlTimeSpan AddValue(this TomlTable table, string key, TimeSpan timeSpan)
        {
            var ts = table.CreateAttachedValue(timeSpan);

            table.AddRow(new TomlKey(key), ts);
            return(ts);
        }
Esempio n. 8
0
#pragma warning restore SA1313 // Parameter names must begin with lower-case letter

        // Internal
        private static T AddTomlObjectInternal <T>(TomlTable table, string key, T o)
            where T : TomlObject
        {
            Assert(o.Root == table.Root);
            table.AddRow(new TomlKey(key), o);
            return(o);
        }
Esempio n. 9
0
        internal static TomlTable CreateFromComplexObject <T>(ITomlRoot root, T obj, TableTypes tableType)
        {
            if (root == null)
            {
                throw new ArgumentNullException(nameof(root));
            }
            if (obj == null)
            {
                throw new ArgumentNullException(nameof(obj));
            }

            TomlTable tt = new TomlTable(root, tableType);

            var members    = root.Settings.GetSerializationMembers(obj.GetType());
            var allObjects = new List <Tuple <string, TomlObject> >();

            foreach (var m in members)
            {
                object val = m.GetValue(obj);
                if (val != null)
                {
                    TomlObject to = TomlObject.CreateFrom(root, val);
                    to.AddComments(root.Settings.GetComments(obj.GetType(), m.Member));
                    tt.AddRow(m.Key, to);
                }
            }

            return(tt);
        }
Esempio n. 10
0
        protected virtual TomlTable CloneForInternal(TomlTable cloneTarget)
        {
            foreach (var r in this.rows)
            {
                cloneTarget.AddRow(r.Key, r.Value.CloneFor(cloneTarget.Root));
            }

            return(CopyComments(cloneTarget, this));
        }
Esempio n. 11
0
        public static TomlTableArray AddTableArray(this TomlTable table, string key, TomlTableArray array)
        {
            if (array.Root != table.Root)
            {
                throw new InvalidOperationException("Cannot add TOML table array to table because it belongs to a different graph root.");
            }

            table.AddRow(new TomlKey(key), array);
            return(array);
        }
Esempio n. 12
0
        internal TomlTable CloneTableFor(ITomlRoot root)
        {
            var tbl = new TomlTable(root, this.TableType);

            foreach (var r in this.rows)
            {
                tbl.AddRow(r.Key, r.Value.CloneFor(root));
            }

            return(tbl);
        }
Esempio n. 13
0
        internal TomlTable TableWithRoot(ITomlRoot root)
        {
            root.CheckNotNull(nameof(root));

            var table = new TomlTable(root, this.TableType);

            foreach (var r in this.rows)
            {
                table.AddRow(r.Key, r.Value.WithRoot(root));
            }

            return(table);
        }
Esempio n. 14
0
        internal static TomlTable CreateFromDictionary(ITomlRoot root, IDictionary dict, TableTypes tableType)
        {
            if (root == null) { throw new ArgumentNullException(nameof(root)); }
            if (dict == null) { throw new ArgumentNullException(nameof(dict)); }

            var tomlTable = new TomlTable(root, tableType);

            foreach (DictionaryEntry r in dict)
            {
                var obj = TomlObject.CreateFrom(root, r.Value);
                tomlTable.AddRow(new TomlKey((string)r.Key), obj);
            }

            return tomlTable;
        }
Esempio n. 15
0
        public static TomlTable CreateAttachedTable(
            this TomlObject rootSource,
            IEnumerable <KeyValuePair <string, TomlObject> > rows,
            TomlTable.TableTypes type = TomlTable.TableTypes.Default)
        {
            var tbl = new TomlTable(rootSource.Root, type);

            foreach (var kvp in rows)
            {
                if (kvp.Value.Root != rootSource.Root)
                {
                    throw new InvalidOperationException(
                              "Cannot create table with rows belonging to a different TOML object graph root.");
                }

                tbl.AddRow(new TomlKey(kvp.Key), kvp.Value);
            }

            return(tbl);
        }
Esempio n. 16
0
        internal static TomlTable CreateFromDictionary <T>(ITomlRoot root, IDictionary <string, T> dict, TableTypes tableType)
        {
            if (root == null)
            {
                throw new ArgumentNullException(nameof(root));
            }
            if (dict == null)
            {
                throw new ArgumentNullException(nameof(dict));
            }

            var tomlTable = new TomlTable(root, tableType);

            foreach (var kvp in dict)
            {
                var obj = TomlObject.CreateFrom(root, kvp.Value);
                tomlTable.AddRow(new TomlKey(kvp.Key), obj);
            }

            return(tomlTable);
        }
Esempio n. 17
0
 public static TomlArray AddArray(this TomlTable table, string key, TomlArray a)
 {
     table.AddRow(new TomlKey(key), a);
     return(a);
 }
Esempio n. 18
0
 public static TomlTable AddTable(this TomlTable table, string key, TomlTable t)
 {
     table.AddRow(new TomlKey(key), t);
     return(t);
 }