I have a class that has numerous properties, two of which are dates:
public class AchFile
{
public DateTime FileDate { get; set; }
public DateTime EffectiveDate { get; set; }
// other properties
public int Insert()
{
//Set file date
if (FileDate == null)
{
FileDate = DateTime.Today;
}
//Set effective date
if (EffectiveDate == null)
{
EffectiveDate = ServiceUtil.NextBusinessDay(InterfaceId, FileDate);
}
return //....
}
}
When I make an instance of the class, I'm not defining EffectiveDate or FileDate. This causes an issue if I call on .Insert() since DateTime objects cannot be null and therefore, those if statements won't be accessed properly.
What would be the best way to update the if statements?
Would the following make sense?
// Default value for a DateTime object is MinValue
if (FileDate == FileDate.MinValue)
{
FileDate = DateTime.Today;
}
if (EffectiveDate == EffectiveDate.MinValue)
{
EffectiveDate = ServiceUtil.NextBusinessDay(InterfaceId, FileDate);
}