Newbie here - Validation Rules question

Newbie here - Validation Rules question

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


kennedystephen posted on Wednesday, May 23, 2007

I'm brand new to CSLA. While refactoring, I changed the name of a property from 'BookName' to just 'Name'. But I neglected to change the corresponding parameter name in ValidationRules.AddRule. Is there a better way to determine the name of the property to validate in the .AddRule method, so that I'd get a design-time error if I'm using a invalid parameter name? Thanks for your help. - Steve

RockfordLhotka replied on Wednesday, May 23, 2007

I have never been able to find a better solution. There's no language construct in VB or C# that corresponds to a property name...

dcleven replied on Wednesday, May 23, 2007

I am far from an expert on CSLA ... but I can't think of any way to make your build break when you have a mismatch.

I write Unit tests for my validation rules and make sure I can break my rules to prove they are working. This way after you refactor you run your unit tests and find your failure.

Doug

 

xal replied on Wednesday, May 23, 2007

Rocky, have you ever considered creating a rule attribute where you can pass the delegate? Maybe a couple of overloads where you can define a friendly name and maybe even default severity?


Andrés

xal replied on Wednesday, May 23, 2007

On the same subject, what about a CanReadPropertyAttribute (and the same for write) where you can pass the roles?



Andrés

RockfordLhotka replied on Wednesday, May 23, 2007

Yes, I’ve considered this – for validation and authorization both.

 

This could be in addition to the current scheme, but not in place of. The current scheme supports good globalization and dynamic configuration (data-driven) of the objects.

 

It would be slower of course, because getting custom attributes is one of, if not the, slowest reflection operation. But if done only for per-type rules it probably wouldn’t make any meaningful difference.

 

Rocky

 

 

From: xal [mailto:cslanet@lhotka.net]
Sent: Wednesday, May 23, 2007 5:19 PM
To: rocky@lhotka.net
Subject: Re: [CSLA .NET] Newbie here - Validation Rules question

 

Rocky, have you ever considered creating a rule attribute where you can pass the delegate? Maybe a couple of overloads where you can define a friendly name and maybe even default severity?


Andrés


Copyright (c) Marimer LLC