ValidationRules.AddRule - GUIDRequired

ValidationRules.AddRule - GUIDRequired

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


Nicholas Trevatt posted on Saturday, December 30, 2006

Hi,

Before I go and write a custom validation rule in my BO's (or extending CSLA) to require a valid GUID exists in properties I just want to make sure I'm not missing something that might already exist.  I can't see anything obvious in Validation.CommonRules so am I on the right track?

Thanks,
Nicholas


Jurjen replied on Saturday, December 30, 2006

Nicholas,

I know of a GuidRequired function in ActiveObjects (ActiveObjects\Rules\ActiveRules.vb) :

  Public Shared Function GuidRequired(ByVal target As Object, ByVal e As RuleArgs) As Boolean
    Dim TestGuid As Guid = New Guid(GetPropertyValue(target, e.PropertyName).ToString)
    If TestGuid.Equals(Guid.Empty) Then
      e.Description = String.Format("{0} required", e.PropertyName)
      Return False
    Else
      Return True
    End If
  End Function

There are some more 'standard' validations for int-range and dates also, check 'm out in the ActiveObjects download on Petar's ActiveObjects site : http://csla.kozul.info/

Hope this helps.
Jurjen.

JoeFallon1 replied on Saturday, December 30, 2006

Sort of. <g>

I created my own class of "common rules" and put it in the same folder as my subclasses of CSLA that all my BOs derive from. I basically copied Rocky's common rules, put them in my own namespace to avoid conflicts, and then enhanced it. This gives ne a single place to put all of mycommon rules. Plus I now have the ability to add things like Property descriptions to my rules so that the broken rule reads: "Account Code is invalid" instead of "Acctcd is invalid".

Plus any suggestions which are made to enhance Rocky's rules can be applied to my rules rigt away without having to wait for the next version of CSLA.

Finally, any new rules you may want to write (like GUID required) can be put in this one place and used for multiple BOs.

Joe

 

Nicholas Trevatt replied on Sunday, December 31, 2006

Thanks Jurjen and Joe for your prompt and most helpful replies!  One of those will do the trick for me I'm sure.

I just want to add that I think the CSLA forum and particularly those people who regularly post helpful replies (including Rocky himself!) are fantastic.  It's one of the many reasons I chose to use CSLA. 

Thanks again,
Nicholas

Copyright (c) Marimer LLC