New Posts New Posts RSS Feed: Generic Emtpy Guid Verifier
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

Generic Emtpy Guid Verifier

 Post Reply Post Reply
Author
BringerOD View Drop Down
DevForce MVP
DevForce MVP
Avatar

Joined: 27-Aug-2010
Location: USA
Posts: 35
Post Options Post Options   Quote BringerOD Quote  Post ReplyReply Direct Link To This Post Topic: Generic Emtpy Guid Verifier
    Posted: 01-Sep-2010 at 9:39pm
Can someone help me make a generic verifier that checks a Guid to see if its equal to Guid.Empty?
 
I am not getting how to write these yet.  They don't make alot of sense to me.
 
I can see how to make one for a specific entity type.
 
The whole process is very complicated for someone who is new to DevForce. 
 
I have read the documentation 3 times now.
 
Bryan
Back to Top
BringerOD View Drop Down
DevForce MVP
DevForce MVP
Avatar

Joined: 27-Aug-2010
Location: USA
Posts: 35
Post Options Post Options   Quote BringerOD Quote  Post ReplyReply Direct Link To This Post Posted: 01-Sep-2010 at 9:42pm
This is how far I got.
 
Just not sure how to get the property to validate. 
 
 

public static class VerifierHelper

{

private static Verifier GuidCannotBeEmpty(EntityProperty pEntityProperty)

{

string description = pEntityProperty.PropertyInfo.Name + " cannot be blank.";

var verifier = new DelegateVerifier<EntityBase>(description, GuidCannotBeEmptyCondition);

verifier.AddTriggers(pEntityProperty.Name);

verifier.VerifierOptions.ExecutionModes = VerifierExecutionModes.InstanceAndOnAfterSetTriggers;

return verifier;

}

private static VerifierResult GuidCannotBeEmptyCondition(

EntityBase entityBase, TriggerContext pTriggerContext, VerifierContext pVerifierContext)

{

if (pTriggerContext != null &&

pTriggerContext.Timing == TriggerTiming.BeforeSet)

{

throw new VerifierException("Verifier not implemented for Preset");

}

return new VerifierResult(?????);

}

}

Back to Top
DenisK View Drop Down
IdeaBlade
IdeaBlade


Joined: 25-Aug-2010
Posts: 708
Post Options Post Options   Quote DenisK Quote  Post ReplyReply Direct Link To This Post Posted: 02-Sep-2010 at 5:49pm
Hi Bryan;

I agree that the Verification chapter needs some work. We have made that a priority to improve the Wiki in the next few months.

As for your question, instead of creating a DelegateVerifier, we should use a PropertyValueVerifier abstract class to create the generic GUID.Empty verifier. The PropertyValueVerifier abstract class is useful when you need to create a custom verifier when comparing objects or values. You can refer to our API Documentation --> IdeaBlade.Validation namespace for more useful Verifier classes.

Here's the code to create your generic GUID.Empty verifier:

private static Verifier CheckForGUIDEmptyVerifier(Type entityType, string propertyName) {
      Verifier v = new GUIDEmptyVerifier(entityType, propertyName);
      v.VerifierArgs.ErrorMessageInfo.ErrorMessage = 
        String.Format("{0} cannot be blank", propertyName);

      return v;
    }
    
    public class GUIDEmptyVerifier : PropertyValueVerifier {

      public GUIDEmptyVerifier(Type pType, String propertyName, String displayName = null, bool? shouldTreatEmptyStringAsNull = null)
        : base(new PropertyValueVerifierArgs(pType, propertyName, false, displayName, shouldTreatEmptyStringAsNull)) {
      }

      protected override VerifierResult VerifyValue(object itemToVerify, object valueToVerify,
        TriggerContext triggerContext, VerifierContext verifierContext) {

        var aGUID = (Guid)valueToVerify;
        var result = (aGUID != Guid.Empty);

        return new VerifierResult(result);
      }
    } 
Back to Top
BringerOD View Drop Down
DevForce MVP
DevForce MVP
Avatar

Joined: 27-Aug-2010
Location: USA
Posts: 35
Post Options Post Options   Quote BringerOD Quote  Post ReplyReply Direct Link To This Post Posted: 03-Sep-2010 at 6:53am
Thanks!
 
That really helped.
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down