that is basically a design matter.
The two dates should be two properties of a IRange<DateTime>
http://fabiomaulo.blogspot.com/2009/10/nhibernatevalidator-extending_26.html
<http://fabiomaulo.blogspot.com/2009/10/nhibernatevalidator-extending_26.html>
2010/2/13 Bear <[email protected]>

> Hi,
>
> I know I can extend the Loquacious configuration from this post;
> http://fabiomaulo.blogspot.com/2009/10/nhibernatevalidator-extending.html
>
> I have successfully created the attribute, validator and extension for
> what I want to do, which is ultimately to compare dates;
>
> Consider this simple example (attribute, validator and extension not
> shown);
>
> public class MyEvent
> {
>     public DateTime StartDate
>     public DateTime EndDate
> }
>
> public class MyEventValidatorDef : ValidatorDef<MyEvent>
> {
>    var someDate = new DateTime(2010,2,13);
>    Define(myEvent => myEvent.StartDate).IsNotPast(someDate)
> }
>
> Now, ideally, I'd like to compare the two dates of MyEvent, I know I
> could do;
>
> ValidateInstance.By((myEvent,context) => {
>
>           bool isValid = true;
>
>           if ( myEvent.StartDate > myEvent.EndDate )
>                     isValid = false;
>
>           return isValid;
> })
>
> BUT, I have other classes that have Dates on them that I want to
> compare, so ideally I want to have a reusable constraints something
> like;
>
> public class MyEventValidatorDef : ValidatorDef<MyEvent>
> {
>    Define(myEvent => myEvent.StartDate).IsNotPast(myEvent =>
> myEvent.EndDate);
>    Define(myEvent => myEvent.EndDate).IsNotBefore(myEvent =>
> myEvent.StartDate);
> }
>
> What's the best way to go about this?
>
> Cheers,
> B.
>
> --
> You received this message because you are subscribed to the Google Groups
> "nhusers" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected]<nhusers%[email protected]>
> .
> For more options, visit this group at
> http://groups.google.com/group/nhusers?hl=en.
>
>


-- 
Fabio Maulo

-- 
You received this message because you are subscribed to the Google Groups 
"nhusers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/nhusers?hl=en.

Reply via email to