public override bool GetNullable(ObjectMapper mapper, MemberAccessor member, out bool isSet) { // Check member [Nullable(true | false)] // NullableAttribute attr1 = member.GetAttribute <NullableAttribute>(); if (attr1 != null) { isSet = true; return(attr1.IsNullable); } // Check member [NullValue(0)] // NullValueAttribute attr2 = member.GetAttribute <NullValueAttribute>(); if (attr2 != null) { return(isSet = true); } // Check type [Nullable(true || false)] // attr1 = (NullableAttribute)TypeHelper.GetFirstAttribute( member.MemberInfo.DeclaringType, typeof(NullableAttribute)); if (attr1 != null) { isSet = true; return(attr1.IsNullable); } // Check type [NullValues(typeof(int), 0)] // object[] attrs = member.GetTypeAttributes(typeof(NullValueAttribute)); foreach (NullValueAttribute a in attrs) { if (a.Type == null && a.Value != null && a.Value.GetType() == member.Type || a.Type != null && a.Type == member.Type) { return(isSet = true); } } if (member.Type.IsEnum) { return(isSet = mapper.MappingSchema.GetNullValue(member.Type) != null); } return(base.GetNullable(mapper, member, out isSet)); }
public override object GetNullValue(ObjectMapper mapper, MemberAccessor member, out bool isSet) { // Check member [NullValue(0)] // NullValueAttribute attr = member.GetAttribute <NullValueAttribute>(); if (attr != null) { isSet = true; return(CheckNullValue(attr.Value, member)); } // Check type [NullValues(typeof(int), 0)] // object[] attrs = member.GetTypeAttributes(typeof(NullValueAttribute)); foreach (NullValueAttribute a in attrs) { if (a.Type == null && a.Value != null && a.Value.GetType() == member.Type || a.Type != null && a.Type == member.Type) { isSet = true; return(CheckNullValue(a.Value, member)); } } if (member.Type.IsEnum) { object value = CheckNullValue(mapper.MappingSchema.GetNullValue(member.Type), member); if (value != null) { isSet = true; return(value); } } isSet = false; return(null); }