private void ProcessDefaultValue <T>(MemberInfo memberInfo, MemberMapping <T> memberMapping, JsonSerializerOptions options)
        {
            DefaultValueAttribute?defaultValueAttribute = memberInfo.GetCustomAttribute <DefaultValueAttribute>();

            if (defaultValueAttribute != null)
            {
                memberMapping.SetDefaultValue(defaultValueAttribute.Value);
            }

            if (memberInfo.IsDefined(typeof(JsonIgnoreIfDefaultAttribute)))
            {
                memberMapping.SetIngoreIfDefault(true);
            }

#if NET5_0
            if (options.DefaultIgnoreCondition == JsonIgnoreCondition.WhenWritingDefault ||
                options.DefaultIgnoreCondition == JsonIgnoreCondition.WhenWritingNull && memberMapping.MemberType.IsClass)
            {
                memberMapping.SetIngoreIfDefault(true);
            }

            JsonIgnoreAttribute?jsonIgnoreAttribute = memberInfo.GetCustomAttribute <JsonIgnoreAttribute>();
            if (jsonIgnoreAttribute != null)
            {
                if (jsonIgnoreAttribute.Condition == JsonIgnoreCondition.WhenWritingDefault ||
                    jsonIgnoreAttribute.Condition == JsonIgnoreCondition.WhenWritingNull && memberMapping.MemberType.IsClass)
                {
                    memberMapping.SetIngoreIfDefault(true);
                }
            }
#endif
        }
Exemple #2
0
        private void ProcessDefaultValue <T>(MemberInfo memberInfo, MemberMapping <T> memberMapping)
        {
            DefaultValueAttribute?defaultValueAttribute = memberInfo.GetCustomAttribute <DefaultValueAttribute>();

            if (defaultValueAttribute != null)
            {
                memberMapping.SetDefaultValue(defaultValueAttribute.Value);
            }

            if (memberInfo.IsDefined(typeof(JsonIgnoreIfDefaultAttribute)))
            {
                memberMapping.SetIngoreIfDefault(true);
            }
        }
Exemple #3
0
        private void ProcessDefaultValue <T>(MemberInfo memberInfo, MemberMapping <T> memberMapping)
        {
            DefaultValueAttribute?defaultValueAttribute = memberInfo.GetCustomAttribute <DefaultValueAttribute>();

            if (defaultValueAttribute != null)
            {
                memberMapping.SetDefaultValue(defaultValueAttribute.Value);
            }

            DataMemberAttribute?dataMemberAttribute = memberInfo.GetCustomAttribute <DataMemberAttribute>();

            if (dataMemberAttribute != null && !dataMemberAttribute.EmitDefaultValue)
            {
                memberMapping.SetIngoreIfDefault(true);
            }
        }