public void ReadJsonProperty(JsonReader reader, JsonSerializer serializer, ModifiableEntity entity, PropertyConverter pc, PropertyRoute parentRoute, bool markedAsModified) { if (pc.CustomReadJsonProperty != null) { pc.CustomReadJsonProperty(new ReadJsonPropertyContext( jsonReader: reader, jsonSerializer: serializer, entity: entity, parentPropertyRoute: parentRoute, propertyConverter: pc )); } else { object?oldValue = pc.GetValue !(entity); var pi = pc.PropertyValidator !.PropertyInfo; var pr = parentRoute.Add(pi); using (JsonSerializerExtensions.SetCurrentPropertyRoute(pr)) { object newValue = serializer.DeserializeValue(reader, pi.PropertyType.Nullify(), oldValue); if (!IsEquals(newValue, oldValue)) { if (!markedAsModified && parentRoute.RootType.IsEntity()) { if (!pi.HasAttribute <IgnoreAttribute>()) { try { //Call attention of developer throw new InvalidOperationException($"'modified' is not set but '{pi.Name}' is modified"); } catch (Exception) { } } } else { AssertCanWrite(pr); if (newValue == null && pc.IsNotNull()) { entity.SetTemporalError(pi, ValidationMessage._0IsNotSet.NiceToString(pi.NiceName())); return; } pc.SetValue?.Invoke(entity, newValue); } } } } }
public void ReadJsonProperty(JsonReader reader, JsonSerializer serializer, ModifiableEntity entity, PropertyConverter pc, PropertyRoute parentRoute, bool markedAsModified) { if (pc.CustomReadJsonProperty != null) { pc.CustomReadJsonProperty(new ReadJsonPropertyContext { JsonReader = reader, JsonSerializer = serializer, Entity = entity, ParentPropertyRoute = parentRoute, PropertyConverter = pc, }); } else { object oldValue = pc.GetValue(entity); var pi = pc.PropertyValidator.PropertyInfo; var pr = parentRoute.Add(pi); using (JsonSerializerExtensions.SetCurrentPropertyRoute(pr)) { object newValue = serializer.DeserializeValue(reader, pi.PropertyType, oldValue); if (!IsEquals(newValue, oldValue)) { if (!markedAsModified && parentRoute.RootType.IsEntity()) { try { //Call attention of developer throw new InvalidOperationException($"'modified' is not set but '{pi.Name}' is modified"); } catch (Exception) { } } else { AssertCanWrite(pr); if (newValue == null && pc.IsNotNull()) //JSON.Net already complaining { return; } pc.SetValue?.Invoke(entity, newValue); } } } } }
public void ReadJsonProperty(JsonReader reader, JsonSerializer serializer, ModifiableEntity entity, PropertyConverter pc, PropertyRoute parentRoute, bool markedAsModified) { if (pc.CustomReadJsonProperty != null) { pc.CustomReadJsonProperty(new ReadJsonPropertyContext { JsonReader = reader, JsonSerializer = serializer, Entity = entity, ParentPropertyRoute = parentRoute, PropertyConverter = pc, }); } else { object oldValue = pc.GetValue(entity); var pi = pc.PropertyValidator.PropertyInfo; var pr = parentRoute.Add(pi); using (JsonSerializerExtensions.SetCurrentPropertyRoute(pr)) { object newValue = serializer.DeserializeValue(reader, pi.PropertyType, oldValue); if (!IsEquals(newValue, oldValue)) { if (!markedAsModified && parentRoute.RootType.IsEntity()) { try { //Call attention of developer throw new InvalidOperationException($"'modified' is not set but '{pi.Name}' is modified"); } catch (Exception) { } } else { AssertCanWrite(pr); if (newValue == null && pc.IsNotNull()) //JSON.Net already complaining return; pc.SetValue?.Invoke(entity, newValue); } } } } }