I have the following property defined:
Private Shared _ApptTimeProperty As PropertyInfo(Of SmartDate) = RegisterProperty(Of SmartDate)(Function(x) CType(x, PatientAppointmentTable).ApptTime, "ApptTime", New SmartDate() With {.FormatString = "G"})
Public Property ApptTime() As System.String Implements IPatientAppointmentTableBase.ApptTime
Get
Return (GetPropertyConvert(Of SmartDate, String)(_ApptTimeProperty))
End Get
Set(ByVal value As System.String)
SetPropertyConvert(Of SmartDate, String)(_ApptTimeProperty, value)
End Set
End Property
This probably has to do with SmartDate being a value type, not a reference type. If you ever set the value to a new SmartDate (which happens in the setter of course) then you'd lose the FormatString value, because the property is now using a completely different SmartDate instance than the default one you provided.
This is one of those quirky things that happens when a value type has properties - they start to feel like a reference type, but they really aren't...
So I changed the getter from :
Return GetPropertyConvert(Of SmartDate, String)(_ApptTimeProperty)
to:
Dim value = GetProperty(Of SmartDate)(_ApptTimeProperty)
Return value.ToString(_ApptTimeProperty.DefaultValue.FormatString)
Unless you can set the static default format string for all SmartDate instances, yes.
No, I can't set the static default I need the other dates to format with "d".
Thanks for the help
Hi Randy,
What version of CSLA are you using?
Check if Utilities.CoerceValue handles SmartDate in a specific way. In later versions there is special handling to only update the value on existing instance rather than assigning a new SmartDate instance to the backing field.
\Core\TypeConverters\SmartDateConverter handles default converting to/from string and datetime values.
I am using version 3.7.
Copyright (c) Marimer LLC