CS C# templates: Why are DateTime properties ReadOnly?

CS C# templates: Why are DateTime properties ReadOnly?

Old forum URL: forums.lhotka.net/forums/t/1364.aspx


Skafa posted on Sunday, October 01, 2006

I noticed that DateTime properties are generated with only a set {} accessor. Why is that?

Remco

rgreen replied on Monday, October 02, 2006

Specifically, which templates are you referring to?

 

RJ

Skafa replied on Monday, October 02, 2006

Sorry,

*CS : CodeSmith, all templates

rasupit replied on Monday, October 02, 2006

Remco,

The DateTime properties are intended to be used for sorting when bind into control such as datagrid.  The set accessor is available through string properties.  Through this property, you can assign empty date.

Ricky

Skafa replied on Tuesday, October 03, 2006

I needed to databind to the DateTime property. (not to the ..String property)

So i created the set accesor, which sets _smartDateProperty.Date to value. Does this cause any unexpected behaviour? It seems to work though.

rgreen replied on Tuesday, October 03, 2006

You should be able to bind to a Smartdate with no problems -- this is a common requirement.

RJ

rasupit replied on Tuesday, October 03, 2006

RJ,

Since SmartDate is now a value type (struct), it should be safe to expose a property as SmartDate.  In Csla 1.x, you'll run into problem where user can do SmartdateProperty.Date = newDateValue and avoid the code inside the set accessor.

However, I don't know how well third party control dealing with SmartDate.  I think a good one will work just fine.

Ricky

rasupit replied on Tuesday, October 03, 2006

If the property does not allow empty date value, then adding set accessor would work just fine.

But then if you don't allow empty date, you should just use DateTime instead of SmartDate.

Ricky

Copyright (c) Marimer LLC