Print Page | Close Window

Validation Bullets

Printed From: IdeaBlade
Category: DevForce
Forum Name: DevForce Classic
Forum Discription: For .NET 2.0
URL: http://www.ideablade.com/forum/forum_posts.asp?TID=484
Printed Date: 24-Oct-2025 at 6:21am


Topic: Validation Bullets
Posted By: orcities
Subject: Validation Bullets
Date Posted: 09-Oct-2007 at 1:27pm
I have just created my first Verifier for an EmailAddress. The problem is that the validation is only being performed when the SaveAll is being used. 
 
On some of my other properties that have set lengths and such they are being thrown immidiately.  I was looking at the documentation and this is the way it is suppose to happen.
 
Is there a reason it is only verifying after a save?

    [VerifierProvider]

    public static IEnumerable<Verifier> GetVerifiers(Object pVerifierProviderContext)

    {

 

        List<Verifier> verifiers = new List<Verifier>();

        verifiers.Add(GetEmailAddressVerifier(Descriptors.Email));

 

        return verifiers;

    }

 

      private static Verifier GetEmailAddressVerifier(PropertyDescriptor pEmailDescriptor)

    {

        return new RegexVerifier(pEmailDescriptor, true, NamedRegexPattern.Email);

    }




Replies:
Posted By: TrevLeyb
Date Posted: 09-Oct-2007 at 2:04pm
I don't know if it will help, but there is a white paper which discusses Verification and how to use it available from the Ideablade website. I think it answers your question on when triggering and verification is fired.
 
I'd be keen on any feedback anyway (I am the author) if it does not cover topics which you feel it should.
 
The link is http://www.ideablade.com/PDF/VerificationWhitepaper.pdf - http://www.ideablade.com/PDF/VerificationWhitepaper.pdf


Posted By: orcities
Date Posted: 09-Oct-2007 at 2:10pm
I will take a look at it and let you know.


Posted By: TrevLeyb
Date Posted: 09-Oct-2007 at 2:32pm
I should have actually answered your question ;-)
 
Verification is only triggered based on the setting of the ExecutionMode which needs to be defined as PreSet, PostSet or Instance. the other thing to check is that you have turned on Before/After validation in the Object Mapper options so that it generates the BeforeSetValue and AfterSetValue calls. It is these calls that execute verification against an object when you set the value through the property.
 
Looking at your code, the verifier will only be called by the Save operation is it will be an INSTANCE verification. You need to explicitly call the verification engine asking it to verify as part of your Getter/Setter for the property that is associated with this verification (if that makes sense).
 
Trevor
 
Originally posted by orcities

I have just created my first Verifier for an EmailAddress. The problem is that the validation is only being performed when the SaveAll is being used. 
 
On some of my other properties that have set lengths and such they are being thrown immidiately.  I was looking at the documentation and this is the way it is suppose to happen.
 
Is there a reason it is only verifying after a save?


Posted By: orcities
Date Posted: 10-Oct-2007 at 7:58am

From looking at the help files I original thought that it always verified. I was wrong. I added the following to get it to verify preset.

private static Verifier GetEmailAddressVerifier(PropertyDescriptor pEmailDescriptor)

    {

        RegexVerifier v = new RegexVerifier(Descriptors.Email, true, NamedRegexPattern.Email);

        v.AddTrigger(pEmailDescriptor);

        v.ExecutionModes = VerifierExecutionModes.OnPresetTriggers;

        return v;

       

    }



Posted By: eileenv
Date Posted: 10-Oct-2007 at 12:26pm

Just to clarify, verifiers that are added via the static method decorated with the [VerifierProvider] attribute, are set with ExecutionModes=InstanceAndOnPostsetTriggers by default.
 
This code would have been sufficient to execute preset:
 

private static Verifier GetEmailAddressVerifier(PropertyDescriptor pEmailDescriptor)

    {

        RegexVerifier v = new RegexVerifier(pEmailDescriptor, true, NamedRegexPattern.Email);

        v.ExecutionModes = VerifierExecutionModes.OnPresetTriggers;

        return v;

       

    }




Print Page | Close Window