public static TomlTable CreateAttached <TValue>(
            this TomlObject rootSource,
            IDictionary <string, TValue> tableData,
            TomlTable.TableTypes type = TomlTable.TableTypes.Default)
        {
            if (tableData is TomlObject)
            {
                throw new ArgumentException(string.Format(TomlObjectCreateNotAllowed2A, nameof(tableData), tableData.GetType()));
            }

            var tbl = TomlTable.CreateFromDictionary(rootSource.Root, tableData, type);

            return(tbl);
        }
Beispiel #2
0
        private static TomlObject CreateFrom(ITomlRoot root, object val, PropertyInfo pi, Type valueType)
        {
            var t         = valueType;
            var converter = root.Settings.TryGetToTomlConverter(t);

            if (converter != null)
            {
                return((TomlObject)converter.Convert(root, val, Types.TomlObjectType));
            }
            else if (val as IDictionary != null)
            {
                return(TomlTable.CreateFromDictionary(root, (IDictionary)val, root.Settings.GetTableType(t)));
            }
            else if (t != Types.StringType && (val as IEnumerable) != null)
            {
                return(CreateArrayType(root, (IEnumerable)val));
            }
            else
            {
                var tableType = root.Settings.GetTableType(t);
                return(TomlTable.CreateFromComplexObject(root, val, tableType));
            }
        }