예제 #1
0
    protected override JsonProperty CreateProperty(MemberInfo member, MemberSerialization memberSerialization)
    {
        JsonProperty property = base.CreateProperty(member, memberSerialization);

        if (property.GetType().GetTypeName() == "object")
        {
            property.ShouldSerialize =
                instance =>
            {
                var value = instance.GetType().GetProperty(property.UnderlyingName).GetValue(instance, null);
                if (value == null)
                {
                    return(false);
                }
                if (value.GetType().GetTypeName() == "object")
                {
                    if (NodeHasValue(value))
                    {
                        return(true);
                    }
                }
                else
                {
                    if (value.GetType().GetTypeName() == "collection")
                    {
                        ICollection enumerable = (ICollection)value;
                        if (enumerable.Count != 0)
                        {
                            return(true);
                        }
                        else
                        {
                            return(false);
                        }
                    }
                    return(true);
                }
                return(false);
            };
        }
        return(property);
    }