Validation rule severity

Validation rule severity

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


ajj3085 posted on Thursday, October 19, 2006

Hi,

I'm at a point where I'm finally going to be using warnings instead of errors as rules.

So, how do I define a warning rule?  Is it only within the rule method?  That would seem to rule out using StringRequired as a warning rule, correct?  Am I missing something else?

Thanks
Andy

JoeFallon1 replied on Thursday, October 19, 2006

When you create your RuleArg instance you can set the Severity to Warning (instead of Error) and then use StringRequired as a warning rule.

Dim x As RuleArgs = New RuleArgs("myProperty")
x.Severity = Csla2.Validation.RuleSeverity.Warning
ValidationRules.AddRule(AddressOf StringRequired, x)

But this brings up a good point.

Rocky - can you create some overloaded methods for the RUleArgs constructor so we can write 1 line of code instead of the 3 (or more if we need to set other values) above.

e.g.

Public Sub New(ByVal propertyName As String, description As String)
  mPropertyName = propertyName
 
mDescription = description
End Sub

Public Sub New(ByVal propertyName As String, description As String, severity As RuleSeverity)
  mPropertyName = propertyName
  mDescription = description
 
mSeverity = severity
End Sub

Joe

ajj3085 replied on Thursday, October 19, 2006

I had overlooked that because i usually use new RuleArgs( "PropertyName" ), didn't think of settng the Serverity there.

Which brings me to a suggestion..  can we have a RuleArgs( string, RuleSeverity ) constructor overload?

Andy

JoeFallon1 replied on Thursday, October 19, 2006

LOL.
You posted while I was editing my first response.

We had the same idea at the same time.

I think in the short run I will add overloads to my own RuleArgs class which derives from Rocky's.

Then I can have the right behavior now and tweak my base class later if Rocky adds the overloaded constructors to the framework.

Public Class MyRuleArgs
 
Inherits RuleArgs

  Public Sub New(ByVal propertyName As String, Optional ByVal description As String = "")
   
MyBase.New(propertyName)
   
Me.Description = description
 
End Sub

  Public Sub New(ByVal propertyName As String, ByVal severity As RuleSeverity, Optional ByVal description As String = "")
   
MyBase.New(propertyName)
   
Me.Description = description
   
Me.Severity = severity
 
End Sub

  Public Sub New(ByVal propertyName As String, ByVal severity As RuleSeverity, ByVal stopProcessing As Boolean, Optional ByVal description As String = "")
   
MyBase.New(propertyName)
   
Me.Description = description
   
Me.Severity = severity
   
Me.StopProcessing = stopProcessing
 
End Sub

End Class

Joe

Copyright (c) Marimer LLC