Extension Method in .NET 2.0, almost

Apr 4, 2008 at 9:20 PM
This workaround does work somewhat. I have not been able to get the extension to change the value of the object it is called on. The following function should write a date to the extended DateTime object:

public static DateTime SafeDate( this DateTime dt, string s)
DateTime tmp;
tmp = ((DateTime.TryParse(s, out tmp)) && (dt != DateTime.MinValue)) ? tmp : new DateTime(599266080000000000);
return tmp;

When called like this:

DateTime date= DateTime.MinValue;

date will still equal DateTime.MinValue and not 01/01/1900 12:00:00AM(the tick value above).