Example #1
0
        public static List <ObjectProperty> FromDatabaseObject(DatabaseObject input)
        {
            var model = new List <ObjectProperty>();

            foreach (var kvp in input.Properties.Where(kvp => kvp.Value != null))
            {
                if (kvp.Value.GetType() == typeof(DatabaseObject))
                {
                    model.Add(new ObjectProperty()
                    {
                        Name = kvp.Key, Value = new ValueObject()
                        {
                            ValueType = ValueType.Object, ObjectProperties = FromDatabaseObject(kvp.Value as DatabaseObject)
                        }
                    });
                }
                else if (kvp.Value.GetType() == typeof(DatabaseArray))
                {
                    model.Add(new ObjectProperty()
                    {
                        Name = kvp.Key, Value = new ValueObject()
                        {
                            ValueType = ValueType.Array, ArrayProperties = FromDatabaseArray(kvp.Value as DatabaseArray)
                        }
                    });
                }
                else
                {
                    model.Add(new ObjectProperty()
                    {
                        Name = kvp.Key, Value = Create(kvp.Value)
                    });
                }
            }

            return(model);
        }
Example #2
0
        public static object FromDictionary(object input)
        {
            var model = new DatabaseObject();

            if (input is Dictionary <string, object> )
            {
                foreach (var kvp in input as Dictionary <string, object> )
                {
                    if (kvp.Value is Dictionary <string, object> )
                    {
                        model.SetProperty(kvp.Key, FromDictionary(kvp.Value as Dictionary <string, object>));
                    }
                    else if (kvp.Value is object[])
                    {
                        var array = new DatabaseArray();

                        foreach (var value in kvp.Value as object[])
                        {
                            array.Add(FromDictionary(value));
                        }

                        model.SetProperty(kvp.Key, array);
                    }
                    else
                    {
                        model.SetProperty(kvp.Key, kvp.Value);
                    }
                }

                return(model);
            }
            else
            {
                return(input);
            }
        }
Example #3
0
 public DatabaseObject Set(string property, DatabaseObject value) => this.SetProperty(property, (object)value);
 /// <summary> Add the given object to the array. </summary>
 public DatabaseArray Add(DatabaseObject value) => Set((uint)this.Properties.Count, value);
 public DatabaseObject GetObject(uint index, DatabaseObject defaultValue) => GetObject(index.ToString(), defaultValue);
Example #6
0
 /// <summary> Create a new database object in the given table with the specified key.
 /// If no key is specified (null), the Database Object will receive an automatically generated key.
 /// </summary>
 /// <param name="table"> The name of the table in which to create the database object. </param>
 /// <param name="key"> The key to assign to the database object. </param>
 /// <param name="dbo"> The database object to create in the table. </param>
 /// <returns> A new instance of the DatabaseObject from which .Save() can be called for future modifications. </returns>
 public void CreateObject(string table, string key, DatabaseObject dbo, Callback <DatabaseObject> successCallback, Callback <PlayerIOError> errorCallback = null)
 => CallbackHandler.CreateHandler(() => this.CreateObject(table, key, dbo), ref successCallback, ref errorCallback);