/// <summary> Determines if the specified property should be serialized. </summary> private bool ShouldPersist(MemberInfo member, object tempValue, object instance) { DefaultValueAttribute defaultValues = (DefaultValueAttribute)ReflectionUtility.GetAttribute(member, typeof(DefaultValueAttribute)); if (defaultValues != null) { return(!Object.Equals(tempValue, defaultValues.Value)); } DefaultValueMemberAttribute defaultMember = (DefaultValueMemberAttribute)ReflectionUtility.GetAttribute(member, typeof(DefaultValueMemberAttribute)); if (defaultMember != null) { return (!Object.Equals ( tempValue, ReflectionUtility.GetMemberValue ( ReflectionUtility.FindSimpleMember(instance.GetType(), defaultMember.MemberName), instance ) )); } return(true); }
/// <summary> Reads the default value for a type's member. </summary> /// <remarks> Throws if no default is provided. </remarks> private static object ReadAttributeDefault(MemberInfo member, object instance) { DefaultValueAttribute defaultValue = (DefaultValueAttribute)ReflectionUtility.GetAttribute(member, typeof(DefaultValueAttribute)); if (defaultValue != null) { return(defaultValue.Value); } if (instance != null) { DefaultValueMemberAttribute defaultMember = (DefaultValueMemberAttribute)ReflectionUtility.GetAttribute(member, typeof(DefaultValueMemberAttribute)); if (defaultMember != null) { return(ReflectionUtility.GetMemberValue(member, instance)); } } throw new BOPException(BOPException.Codes.DefaultNotSpecified, member.Name, member.DeclaringType.Name); }