public override void WriteJson(object data, JsonWriter writer)
        {
            var po = (ParseObject)data;
            writer.StartObject ();

            lock (po.property_lock) {
                foreach (var key in po.updated_properties) {
                    writer.WriteKey (key);

                    var value = po.properties [key];
                    if (value is DateTime) {
                        throw new NotImplementedException ("Write DateTime");
                    } else if (value is byte []) {
                        throw new NotImplementedException ("Write byte [] data");
                    } else if (value is ParseObject) {
                        throw new NotImplementedException ("Write pointer to ParseObject");
                    } else {
                        writer.WriteValue (value);
                    }
                }
            }

            writer.EndObject ();
        }
Exemple #2
0
 public abstract void WriteJson(object data, JsonWriter writer);
Exemple #3
0
 public override void WriteJson(object data, JsonWriter writer)
 {
     writer.WriteObject ((IDictionary<string, object>)data);
 }
Exemple #4
0
 public override void WriteJson(object data, JsonWriter writer)
 {
     var type = data.GetType ();
     writer.StartObject ();
     foreach (var prop in type.GetProperties (BindingFlags.Public | BindingFlags.Instance)) {
         if (prop.IsSpecialName)
             continue;
         writer.WriteKey (prop.Name);
         writer.WriteValue (prop.GetValue (data, null));
     }
     foreach (var field in type.GetFields (BindingFlags.Public | BindingFlags.Instance)) {
         if (field.IsSpecialName || field.IsNotSerialized)
             continue;
         writer.WriteKey (field.Name);
         writer.WriteValue (field.GetValue (data));
     }
     writer.EndObject ();
 }
Exemple #5
0
 public override void WriteJson(object data, JsonWriter writer)
 {
     writer.WriteArray ((IList)data);
 }
Exemple #6
0
 public static void ToJson(this object foo, JsonWriter writer)
 {
     writer.WriteValue (foo);
 }
        public override Future WriteJson(object data, JsonWriter writer)
        {
            var po = (ParseObject)data;

            lock (po.property_lock) {

                // fold in our [ParseKey] properties
                if (po.property_keys != null) {
                    foreach (var kv in po.property_keys) {
                        object dictValue = null;
                        po.properties.TryGetValue (kv.Key, out dictValue);
                        var propValue = kv.Value.GetValue (data, null);
                        if ((propValue != null && !propValue.Equals (dictValue)) ||
                            (propValue == null && dictValue != null)) {
                            po.properties [kv.Key] = propValue;
                            po.updated_properties.Add (kv.Key);
                        }
                    }
                }

                if (po.updated_properties.Count == 0)
                    return Future.Fulfilled;

                writer.StartObject ();

                foreach (var key in po.updated_properties) {
                    if (key == null)
                        continue; //FIXME: this really should never happen

                    writer.WriteKey (key);

                    var value = po.properties [key];
                    if (value is DateTime) {
                        writer.StartObject ();
                        writer.WriteKey ("__type");
                        writer.WriteString ("Date");
                        writer.WriteKey ("iso");
                        writer.WriteString (ToString ((DateTime)value));
                        writer.EndObject ();
                        continue;

                    } else if (value is byte []) {
                        throw new NotImplementedException ("Write byte [] data");

                    } else if (value is ParseObject) {
                        var obj = (ParseObject)value;
                        ParseTypeAttribute pta = null;
                        if ((pta = (ParseTypeAttribute)obj.GetType ().GetCustomAttributes (typeof (ParseTypeAttribute), true).SingleOrDefault ()) == null
                            || !pta.Inline)
                        {
                            obj.Save ().Wait ();
                            writer.StartObject ();
                            writer.WriteKey ("__type");
                            writer.WriteString ("Pointer");
                            writer.WriteKey ("className");
                            writer.WriteString (obj.pointerClassName);
                            writer.WriteKey ("objectId");
                            writer.WriteString (obj.ObjectId);
                            writer.EndObject ();
                            continue;
                        }

                    } else if (value is ParseFile) {
                        var file = (ParseFile)value;
                        file.Save ().Wait ();
                        writer.StartObject ();
                        writer.WriteKey ("__type");
                        writer.WriteString ("File");
                        writer.WriteKey ("name");
                        writer.WriteString (file.RemoteName);
                        writer.EndObject ();
                        continue;

                    } else if (value is ParseGeoPoint) {
                        var geo = (ParseGeoPoint)value;
                        writer.StartObject ();
                        writer.WriteKey ("__type");
                        writer.WriteString ("GeoPoint");
                        writer.WriteKey ("latitude");
                        writer.WriteValue (geo.Latitude);
                        writer.WriteKey ("longitude");
                        writer.WriteValue (geo.Longitude);
                        writer.EndObject ();
                        continue;
                    }

                    writer.WriteValue (value).Wait ();
                }

                writer.EndObject ();
            }

            return Future.Fulfilled;
        }
Exemple #8
0
 public static Future ToJson(this object foo, JsonWriter writer)
 {
     return writer.WriteValue (foo);
 }
Exemple #9
0
 public static string ToJson(this object foo)
 {
     var writer = new JsonWriter ();
     foo.ToJson (writer);
     return writer.ToString ();
 }
Exemple #10
0
 public static Future<string> ToJson(this object foo)
 {
     var writer = new JsonWriter ();
     foo.ToJson (writer).Wait ();
     return writer.ToString ();
 }
Exemple #11
0
 public override Future WriteJson(object data, JsonWriter writer)
 {
     return writer.WriteObject ((IDictionary<string, object>)data);
 }
Exemple #12
0
 public override Future WriteJson(object data, JsonWriter writer)
 {
     return writer.WriteArray ((IList)data);
 }
Exemple #13
0
 public abstract Future WriteJson(object data, JsonWriter writer);
 internal string Translate(Expression expression)
 {
     json = new JsonWriter ();
     Visit(expression);
     return json.ToString ();
 }