コード例 #1
0
        public static MutableDocument ToDocument(this Couchbase.Lite.MutableDictionaryObject dico, string id, MutableDocument document = null)
        {
            if (document == null)
            {
                document = new MutableDocument(id);
            }

            foreach (string key in dico.Keys)
            {
                string typeOfObject = dico.GetValue(key)?.GetType().ToString();
                switch (typeOfObject)
                {
                case "System.Int64": document.SetLong(key, dico.GetLong(key)); break;

                case "System.Int32": document.SetInt(key, dico.GetInt(key)); break;

                case "Couchbase.Lite.IMutableDictionary":
                case "Couchbase.Lite.MutableDictionaryObject": document.SetDictionary(key, dico.GetDictionary(key)); break;

                case "System.String": document.SetString(key, dico.GetString(key)); break;

                case "System.DateTime": document.SetDate(key, dico.GetDate(key)); break;

                case "Couchbase.Lite.MutableArrayObject": document.SetArray(key, dico.GetArray(key)); break;

                default:
                    document.SetValue(key, dico.GetValue(key));
                    break;
                }
            }

            return(document);
        }
コード例 #2
0
        public static Commune ToCommune(this Couchbase.Lite.MutableDictionaryObject dico)
        {
            Commune commune = new Commune()
            {
                Num          = dico.GetInt("num"),
                Libelle      = (dico.GetString("libelle") ?? ""),
                CodePostal   = (dico.GetString("codePostal") ?? ""),
                PayCode      = (dico.GetString("payCode") ?? ""),
                DateCreation = Convert.ToDateTime(dico.GetString("dateCreation")),
                DateModif    = Convert.ToDateTime(dico.GetString("dateModif"))
            };

            return(commune);
        }
コード例 #3
0
        private MutableDocument([NotNull] MutableDocument other)
            : this((Document)other)
        {
            var dict = new MutableDictionaryObject();

            if (other._dict != null)
            {
                foreach (var item in other._dict)
                {
                    dict.SetValue(item.Key, MutableCopy(item.Value));
                }
            }

            _dict = dict;
        }
コード例 #4
0
        public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
        {
            var dict = new MutableDictionaryObject();

            if (reader.TokenType == JsonToken.StartObject)
            {
                reader.Read();
            }

            while (reader.TokenType != JsonToken.EndObject && reader.Read())
            {
                var key = reader.Value as string;
                if (key == null)
                {
                    throw new InvalidDataException("Non-string or null key in data to be deserialized");
                }

                reader.Read();
                var value = reader.Value;
                dict.SetValue(key, value);
            }

            return(dict);
        }
コード例 #5
0
        public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
        {
            var dict = new MutableDictionaryObject();

            if (reader.TokenType == JsonToken.StartObject)
            {
                reader.Read();
            }

            while (reader.TokenType != JsonToken.EndObject && reader.Read())
            {
                var key = reader.Value as string;
                if (key == null)
                {
                    throw new InvalidDataException(CouchbaseLiteErrorMessage.InvalidValueToBeDeserialized);
                }

                reader.Read();
                var value = reader.Value;
                dict.SetValue(key, value);
            }

            return(dict);
        }