I'm sure someone has overcome this but I can't find anything in the forums (except for the same problem - no solution though).
I've got a SmartDate and when I set the .Text to an invalid date it throws an ArgumentException. I understand that this is documented and by design.
But... if someone sets an invalid date, surely it would be better to add a broken rule rather than throw an exception?! Because I'm exposing my business objects through some services I'm just dealing with string as a transport type and I can't trust that the service consumer is going to constrain the UI to only allow valid date formats.
Because an exception is being thrown I get none of the goodness with the broken rules functionality - no property name, no invalid value, etc to tell the client what really went wrong. At the moment I have to parse the exception message just to get the name of the property to send back to the service consumer... yuch.
My thinking is that I need to extend SmartDate so that any invalid cast in the .Text setter causes the storage of the invalid value (for later use in error messages) and creates a new broken rule. Is this the best way to handle it?
Thanks
Justin
Rather than deal with all of that I decided to just set invalid dates to blank. I also check for SQL Server smalldattime dates.
Here is the modified code:
'JF 10/12/06 - The SmartDate Structure cannot be inherited so we need to change CSLA2 itself.
'If Value is not a date then set it to Date.MinValue so that "" will be returned.
'Effectively this blanks out invalid values in the UI.
'Also, ensure that Value is in the range 1/1/1900 to 6/6/2079 else SQL Server smalldatetime value is violated.
Public
Shared Function StringToDate( _Joe
I want my business objects to behave the way Justin describes them. I'm using CSLA 3.0.4.
I'm looking for advice on my approach. I've already created a SmartNullable(T) which is based on Nullable(T) with the addition of allowing string-value assignment and tracking invalid values/state.
A validation rule will be able to ask the structure if it has an invalid value and provide an appropriate description (e.g. 'hello world' is not a valid date.)
Does this seem like a well-designed solution?
Copyright (c) Marimer LLC