Xamarin.Parse.Json.JsonWriter.WriteString C# (CSharp) Méthode

WriteString() public méthode

public WriteString ( string str ) : void
str string
Résultat void
        public void WriteString(string str)
        {
            WriteCommaIfNecessary ();
            buffer.Append ('"');
            for (var i = 0; i < str.Length; i++) {
                var next = str [i];
                switch (next) {

                case '\a' : buffer.Append ("\\a"); break;
                case '\b' : buffer.Append ("\\b"); break;
                case '\f' : buffer.Append ("\\f"); break;
                case '\n' : buffer.Append ("\\n"); break;
                case '\r' : buffer.Append ("\\r"); break;
                case '\t' : buffer.Append ("\\t"); break;
                case '\v' : buffer.Append ("\\v"); break;
                case '\\' : buffer.Append ("\\\\"); break;
                case '"'  : buffer.Append ("\\\""); break;
                default   : buffer.Append (next); break;
                }
            }
            buffer.Append ('"');
            next_needs_comma = true;
        }

Usage Example

        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;
        }