I want to set all DateTime properties of my object to a default date. However, if I try do set the values through reflection I get the exception: "Object does not match target type."
private void SetDefaultValues()
{
DateTime dt = DateTime.Parse("1/1/2000", new CultureInfo("en-US", true));
foreach (PropertyInfo p in this.GetType().GetProperties())
{
if (p.PropertyType.FullName == "System.DateTime")
{
p.SetValue(dt, typeof(DateTime), null);
}
}
}
Am I doing / thinking something fundamentally incorrect?