I have a ReadOnlyList and a BusinessBase class that contains Event information something like this.
public static readonly PropertyInfo<SmartDate> StartProperty = RegisterProperty<SmartDate>(p => p.Start, "Start");
public string Start
{
get { return GetPropertyConvert<SmartDate, String>(StartProperty); }
set { SetPropertyConvert<SmartDate, String>(StartProperty, value); }
}
public static readonly PropertyInfo<SmartDate> EndProperty = RegisterProperty<SmartDate>(p => p.End, "End");
public string End
{
get { return GetPropertyConvert<SmartDate, String>(EndProperty); }
set { SetPropertyConvert<SmartDate, String>(EndProperty, value); }
}
Hi skeeler,
I also noticed SmartDate just shows the date. After all it's SmartDate and not SmartDateTime
For simple auditing purposes - i.e. CreatedOn / ChangedOn - I use DateTime and set the same value on both properties when the object is created. As these properties can never be null I don't need any "smartness" here.
They are going to be a nullable datetime. I guess I'll have to just do the ladder.
Thanks for the help.
Hi,
SmartDate supports format strings and the default format is"d".
Se also Standard Date and Time Format strings
Try this code:
var sd = new SmartDate(); Debug.Print("default format: {0}", sd.FormatString); sd.FormatString = "g"; Debug.Print("new format: {0}", sd.FormatString); sd.Text = DateTime.Now.ToString("g"); Debug.Print(sd.Date.ToString("g")); Debug.Print(sd.Text);
Gives this result on my culture:
default format: d
new format: g
04.05.2013 12:08
04.05.2013 12:08
when the datetime format is changed to "g" = General date/time pattern (short time).
Hi Jonny. I have this special case where I need to select Date + Time as a property for user input.
On my BusinessBase constructed class, I declare the property like this:
private static PropertyInfo<SmartDate> StartDateTimeProperty = RegisterProperty<SmartDate>(c => c.StartDateTime, "Start Date & Time", new SmartDate(DateTime.Now));
public string StartDateTime
{
get
{
var tempSD = GetProperty(StartDateTimeProperty);
tempSD.FormatString = "G";
string retValue = tempSD.Text;
return retValue;
//return GetPropertyConvert<SmartDate, string>(StartDateTimeProperty);
}
set { SetPropertyConvert<SmartDate, string>(StartDateTimeProperty, value); }
}
This is working fine but I think there may be a better way consisting of somehow being able to assign [StartDateTimeProperty.FormatString] without deriving a new [struct] from SmartDate. It would be more elegant. Is there any way of doing this?
Thanks,
Troncho
Hi,
You can specify the custom format in RegisterProperty:
private static PropertyInfo<SmartDate> StartDateTimeProperty =
RegisterProperty(c => c.StartDateTime, "Start Date & Time",
new SmartDate(DateTime.Now) {FormatString = "G"});
Nice! I knew there had to be a better way
Once again, thanks Jonny!
Copyright (c) Marimer LLC