private void DeserializeReadOnly(PropertyMapper prop, object obj, BsonDocument value) { var val = value[prop.FieldName]; if (!val.IsNull) { // check if has a custom deserialize function if (prop.Deserialize != null) { prop.Setter(obj, prop.Deserialize(val, this)); } else { if (val.IsArray && !prop.PropertyType.IsArray) { //I would change this for ICollection, but that is not possible in .net 2 IList objectCollection = (IList)obj.GetType().GetProperty(prop.PropertyName).GetValue(obj, null); IList databaseCollection = (IList)Deserialize(prop.PropertyType, val); foreach (var item in databaseCollection) { objectCollection.Add(item); } } } } }
private void DeserializeWithSetter(PropertyMapper prop, object obj, BsonDocument value) { var val = value[prop.FieldName]; if (!val.IsNull) { // check if has a custom deserialize function if (prop.Deserialize != null) { prop.Setter(obj, prop.Deserialize(val, this)); } else { prop.Setter(obj, this.Deserialize(prop.PropertyType, val)); } } }