public static object Convert(JavaDictionary dict, Type returnType, object objectToModify = null) { var ret = objectToModify ?? Activator.CreateInstance(returnType); if (ret is IDictionary nodeDict) { var type = nodeDict.GetType(); var keyType = GetItemType(type, 0); var dictType = GetItemType(type, 1); var keysToRemove = new List <object>(); foreach (var key in nodeDict.Keys) { keysToRemove.Add(key); } foreach (DictionaryEntry itemData in dict) { var key = Convert(itemData.Key, keyType); keysToRemove.Remove(key); if (nodeDict.Contains(key)) { var item = Convert(itemData.Value, dictType, nodeDict[key]); } else { var val = Convert(itemData.Value, dictType); nodeDict.Add(key, val); } } foreach (var keyToRemove in keysToRemove) { if (nodeDict.Contains(keyToRemove)) { nodeDict.Remove(keyToRemove); } } } foreach (var item in TypePropertyHelper.GetFirebaseProperties(returnType)) { //if (!item.Value.CustomAttribute.ReadOnly) { var prp = item.Value.Property; var key = (string)item.Key; if (dict.Contains(key)) { var data = dict[key]; var internalData = prp.GetValue(ret); var newdata = Convert(data, prp.PropertyType, internalData); try { prp.SetValue(ret, newdata); } catch (System.Exception ex) { var i = ex; } } } } return(ret); }