SmartDateConverter bug

SmartDateConverter bug

Old forum URL:

RRorije posted on Friday, February 26, 2010


I am not completely sure whether I need to post this here, or in a bug database which I can not find.I notice that there is a difference in converting a smartdate.

1. TypeDescriptor.GetConverter(typeof(Csla.SmartDate)).ConvertTo(new SmartDate(), typeof(DateTime?))
2. (DateTime?) new SmartDate()

1. returns DateTime.MinValue
2. returns null.

My proposed solution is to change the SmartDateConverter class line 97 to
return (DateTime?) sd;

Please correct me, if there is some flaw in my reasoning.

RockfordLhotka replied on Friday, February 26, 2010

Thanks, added to the bug list

(The bug list used to have a public interface - but in less than 10 days after making it public, spammers automated an attack and flooded the database with spam. There should really be a way to deal with spammers, something involving substantial physical discomfort and exile from any contact with their fellow humans.)

JonnyBee replied on Thursday, September 09, 2010


I have looked into ths issue and it is not a problem/bug with the SmartDateConverter class.

The code for:
      DateTime? dt1 = (DateTime?) new SmartDate();
      Debug.Print(((DateTime?)new SmartDate()).ToString());

doesn't hit the SmartDateConverter class but executes the static implicit operator in SmartDate:

    /// <summary>
    /// Convert a SmartDate to a nullable DateTime.
    /// </summary>
    /// <param name="obj1">SmartDate value.</param>
    public static implicit operator System.DateTime?(SmartDate obj1)
      return obj1.ToNullableDate();

    /// <summary>
    /// Gets the value as a DateTime?.
    /// </summary>
    public DateTime? ToNullableDate()
      if (this.IsEmpty)
        return new DateTime?();
        return new DateTime?(this.Date);

So the rule SmartDate implements is that an Empty SmartDate converts to a DataTime that is null.

I have discussed this with Rocky and concluded that we do not want to change this code for now.


Copyright (c) Marimer LLC