Ejemplo n.º 1
0
        protected override JsonProperty CreateProperty(MemberInfo member, MemberSerialization memberSerialization)
        {
            switch (member)
            {
            case PropertyInfo propertyInfo:
                var property = TypeCache.GetDeclaredProperty(propertyInfo);
                if (property == null || property.Hidden)
                {
                    return(null);
                }
                var p = base.CreateProperty(propertyInfo, memberSerialization);
                if (property.IsDateTime)
                {
                    var format = property.CustomDateTimeFormat ?? "O";
                    if (!DateTimeConverters.TryGetValue(format, out var converter))
                    {
                        converter = DateTimeConverters[format] = new DateTimeConverter(format);
                    }
                    p.Converter = converter;
                }
                p.Writable               = property.IsWritable;
                p.NullValueHandling      = property.HiddenIfNull ? NullValueHandling.Ignore : NullValueHandling.Include;
                p.ObjectCreationHandling = property.ReplaceOnUpdate ? ObjectCreationHandling.Replace : ObjectCreationHandling.Auto;
                p.PropertyName           = property.Name;
                p.Order         = property.Order;
                p.ValueProvider = new DefaultValueProvider(property);
                return(p);

            case FieldInfo fieldInfo:
                if (fieldInfo.RESTableIgnored())
                {
                    return(null);
                }
                var f = base.CreateProperty(fieldInfo, memberSerialization);
                f.PropertyName = fieldInfo.RESTableMemberName();
                return(f);

            default: return(null);
            }
        }