Ok, I think I found a way to do this. Does anyone see a problem with the use of FieldManager.GetRegisteredProperties(); in the method below?
protected TimeSpan ToLocalTime()
{
TimeSpan offset = new TimeSpan(0);
this.ValidationRules.SuppressRuleChecking = true;
//Get list of all Managed properties
List<Csla.Core.IPropertyInfo> l = FieldManager.GetRegisteredProperties();
if (l != null)
{
foreach (Csla.Core.IPropertyInfo item in l)
{
Csla.PropertyInfo<DateTimeOffset?> propInfoNull;
Csla.PropertyInfo<DateTimeOffset> propInfo;
propInfoNull = item as Csla.PropertyInfo<DateTimeOffset?>;
propInfo = item as Csla.PropertyInfo<DateTimeOffset>;
//If the PropertyInfo type is a DateTimeOffset? (nullable)
if (propInfoNull != null)
{
if (FieldManager.FieldExists(item))
{
DateTimeOffset? dtoNullable = null;
dtoNullable = ReadProperty<DateTimeOffset?>(propInfoNull);
if (dtoNullable.HasValue)
{
dtoNullable = dtoNullable.Value.ToLocalTime();
//Must Clear current value because dates shifted to different timezones
//compare equal and CSLA will not update fields whos new value is equal to current value.
//ex. "5/10/2007 10:33:52 AM -05:00" == "5/10/2007 3:33:52 PM +00:00"
LoadProperty<DateTimeOffset?>(propInfoNull, null);
LoadProperty<DateTimeOffset?>(propInfoNull, dtoNullable);
offset = dtoNullable.Value.Offset;
}
}
}
//If the PropertyInfo type is a DateTimeOffset
if (propInfo != null)
{
if (FieldManager.FieldExists(item))
{
DateTimeOffset dto;
dto = ReadProperty<DateTimeOffset>(propInfo);
dto = dto.ToLocalTime();
//Must Clear current value because dates shifted to different timezones
//compare equal and CSLA will not update fields whos new value is equal to current value.
//ex. "5/10/2007 10:33:52 AM -05:00" == "5/10/2007 3:33:52 PM +00:00"
LoadProperty<DateTimeOffset>(propInfo, new DateTimeOffset(1970, 1, 1, 0, 0, 0, 1, new TimeSpan(0)));
LoadProperty<DateTimeOffset>(propInfo, dto);
offset = dto.Offset;
}
}
}
}
ValidationRules.SuppressRuleChecking = false;
return offset;
}