private static void Validate(ListNode listNode) { if (listNode.Metadata.HasFlag(BindingMetadataFlags.Item) && listNode.Metadata.Parent.Composition?.Add == null) { throw BindingException.FromMetadata(listNode.Metadata.Parent, $"List add method not found."); } }
private Expression GetValueReaderProxy(IBindingValueInfo valueInfo) { Expression value = valueInfo.Value; if (value.Type != typeof(object) && value.Type != typeof(string)) { throw BindingException.FromMetadata(valueInfo.Metadata, $"Cannot deserialize JSON from type '{value.Type.GetSanitizedName()}'."); } Expression nullCheck = null; if (valueInfo.CanBeDbNull) { nullCheck = Expression.TypeIs(value, typeof(DBNull)); } if (valueInfo.CanBeNull) { Expression isNull = Expression.ReferenceEqual(value, Expression.Constant(null, value.Type)); if (nullCheck == null) { nullCheck = isNull; } else { nullCheck = Expression.AndAlso(nullCheck, isNull); } } if (value.Type == typeof(object)) { value = Expression.Convert(value, typeof(string)); } Expression jsonValue = this.GetJsonDeserializer(valueInfo.Metadata, value, valueInfo.Helper); if (nullCheck != null) { return(Expression.Condition(nullCheck, Expression.Default(jsonValue.Type), jsonValue)); } return(jsonValue); }