Hi,
I’m trying to jump from the DB19 version to the db 21, in my Xamrin c# project, using couchbase lite 2.0.
to be able to save my documents correctly, I coded this methode :
private static void DicoToDocument(Document document, IDictionaryObject dico)
{
foreach (string key in dico.Keys)
{
string typeOfObject = dico.GetObject(key).GetType().ToString();
switch(typeOfObject)
{
case "System.Int64": document.Set(key, dico.GetLong(key)); break;
case "System.Int32": document.Set(key, dico.GetInt(key));break;
case "Couchbase.Lite.IDictionaryObject":
case "Couchbase.Lite.DictionaryObject": document.Set(key, dico.GetDictionary(key)); break;
case "System.String": document.Set(key, dico.GetString(key)); break;
case "System.DateTime": document.Set(key, dico.GetDate(key)); break;
case "Couchbase.Lite.ArrayObject": document.Set(key, dico.GetObject(key)); break;
default:
Debugger.Break();
document.Set(key, dico.GetObject(key));
break;
}
}
}
And I’m calling it like that :
Document document = new Document(docId); // db19
IDictionaryObject dico = aSauver.DocumentInitialize();
DicoToDocument(document, dico);
_dataBase.Save(document);
I just changed my NuGet package version to db21, applied the documentated changes for the db20 version, and realised that the class IDictionaryObject don’t have the GetObject(key) methode anymore. As shown upper, I’m using it to obtain the type of the stored object.
So I’have 2 questions :
-
How can I do to obtain the type of the stored object since the db21 version ?
-
I’m not quite sure i’m using the proper way to store my objects in documents. It’s more simple with the couchbase Netclient librery, I just have to do so :
communes.ForEach(commune => { Document<Commune> document = new Document<Commune>(); document.Content = commune.ToCommune(); document.Id = $"commune_{commune.Num}"; _couchbaseConnector.BucketGiver().Insert(document); });
I don’t have to play with the dictionnary. Is teire an equivalente way to do so in couchbase Lite ?
Thank you
Steeve