Exemplo n.º 1
0
 public NCMBObject SetAcl(NCMBAcl acl)
 {
     _acl = acl;
     return(this);
 }
Exemplo n.º 2
0
        public void Sets(JObject query)
        {
            foreach (KeyValuePair <string, JToken> key in query)
            {
                if (key.Key == "__type")
                {
                    continue;
                }
                if (key.Key == "className")
                {
                    continue;
                }
                switch (key.Value.Type)
                {
                case JTokenType.String:
                    this.Set(key.Key, (string)key.Value);
                    break;

                case JTokenType.Integer:
                    this.Set(key.Key, (int)key.Value);
                    break;

                case JTokenType.Boolean:
                    this.Set(key.Key, (Boolean)key.Value);
                    break;

                case JTokenType.Date:
                    this.Set(key.Key, (DateTime)key.Value);
                    break;

                case JTokenType.Array:
                    this.Set(key.Key, (JArray)key.Value);
                    break;

                case JTokenType.Null:
                    this._fields[key.Key] = null;
                    break;

                default:
                    var obj = (JObject)key.Value;
                    if (obj.ContainsKey("__type") && ((string)obj["__type"]) == "Date")
                    {
                        this.Set(key.Key, DateTime.Parse((string)obj["iso"]));
                    }
                    else if (obj.ContainsKey("__type") && ((string)obj["__type"]) == "Object")
                    {
                        var ChildObject = new NCMBObject((string)obj["className"]);
                        ChildObject.Sets((JObject)obj);
                        this.Set(key.Key, ChildObject);
                    }
                    else if (obj.ContainsKey("__type") && ((string)obj["__type"]) == "Relation")
                    {
                        // Do nothing
                    }
                    else if (obj.ContainsKey("__type") && ((string)obj["__type"]) == "GeoPoint")
                    {
                        var data = (JObject)key.Value;
                        var geo  = new NCMBGeoPoint((double)data["latitude"], (double)data["longitude"]);
                        this.Set(key.Key, geo);
                    }
                    else if (key.Key == "acl")
                    {
                        var acl = new NCMBAcl();
                        acl.Sets((JObject)key.Value);
                        this.SetAcl(acl);
                    }
                    else
                    {
                        this.Set(key.Key, (JObject)key.Value);
                    }
                    break;
                }
            }
        }