public override object DeserializeMap(DeserializationContext context, IDictionary <string, Value> values) { object ret = _createInstance(); foreach (var pair in values) { if (_writableProperties.TryGetValue(pair.Key, out var property)) { property.SetValue(context, pair.Value, ret); } else { switch (_attribute.UnknownPropertyHandling) { case UnknownPropertyHandling.Ignore: break; case UnknownPropertyHandling.Warn: context.Database.LogWarning($"No writable property for Firestore field {pair.Key} in type {TargetType.FullName}"); break; case UnknownPropertyHandling.Throw: throw new ArgumentException($"No writable property for Firestore field {pair.Key} in type {TargetType.FullName}"); } } } AttributedIdAssigner.MaybeAssignId(ret, context.DocumentReference); return(ret); }
public override object DeserializeMap(DeserializationContext context, IDictionary <string, Value> values) { // TODO: Consider using a compiled expression tree for this. object ret; try { ret = _ctor.Invoke(parameters: null); } catch (TargetInvocationException e) when(e.InnerException != null) { throw e.InnerException; } foreach (var pair in values) { if (_writableProperties.TryGetValue(pair.Key, out var property)) { property.SetValue(context, pair.Value, ret); } else { switch (_attribute.UnknownPropertyHandling) { case UnknownPropertyHandling.Ignore: break; case UnknownPropertyHandling.Warn: context.Database.LogWarning($"No writable property for Firestore field {pair.Key} in type {TargetType.FullName}"); break; case UnknownPropertyHandling.Throw: throw new ArgumentException($"No writable property for Firestore field {pair.Key} in type {TargetType.FullName}"); } } } AttributedIdAssigner.MaybeAssignId(ret, context.DocumentReference); return(ret); }