/// <summary> /// Overrides the base method to return null if all properties are null for a string format. /// If the values are not properties then it returns false, so that they would still be added /// to the list that is passed to the <see cref="ListToString"/> method. /// </summary> /// <param name="value">The value to check for null.</param> /// <param name="format">The value format, for which the null check is performed.</param> /// <returns>True if the value is considered to be null for the given format, otherwise false.</returns> public override bool IsValueNull(object value, ValueFormat format) { if (format.IsString()) { List <object> props = value as List <object>; if (props != null && props.All(p => p is DataProperty)) { return(props.Cast <DataProperty>().All(p => p.IsNull())); } } return(false); }
/// <summary> /// Converts a single value to a given format. For typed formats /// this method tries to convert various types of values to a nullable DateTime. /// For string formats it displays the internal DateTime formatted according /// to the specified <see cref="Format"/>. /// </summary> /// <param name="value">A single value to convert to the given format.</param> /// <param name="format">The value format to convert the value to.</param> /// <returns>The value converted to the given format.</returns> protected override object ConvertValue(object value, ValueFormat format) { if (format.IsTyped()) { if (value is DateTime?) { return(value); } if (value is DateTime) { return((DateTime?)value); } if (IsValueNull(value, format)) { return(null); } DateTime dt; if (DateTime.TryParse(Convert.ToString(value), out dt)) { return(dt); } if (format == ValueFormat.Transport) { return(null); } } if (format.IsString()) { DateTime?dt = value as DateTime?; if (dt == null && value is DateTime) { dt = (DateTime)value; } if (dt != null && dt.HasValue && !string.IsNullOrEmpty(Format)) { return(dt.Value.ToString(Format)); } } return(base.ConvertValue(value, format)); }
/// <summary> /// Overrides the base method to return null if all properties are null for a string format. /// If the values are not properties then it returns false, so that they would still be added /// to the list that is passed to the <see cref="ListToString"/> method. /// </summary> /// <param name="value">The value to check for null.</param> /// <param name="format">The value format, for which the null check is performed.</param> /// <returns>True if the value is considered to be null for the given format, otherwise false.</returns> public override bool IsValueNull(object value, ValueFormat format) { if (format.IsString()) { List<object> props = value as List<object>; if (props != null && props.All(p => p is DataProperty)) return props.Cast<DataProperty>().All(p => p.IsNull()); } return false; }