CodeSmith Community
Your Code. Your Way. Faster!

deep validation

Latest post 10-18-2007 1:50 PM by Polar. 1 replies.
  • 08-24-2007 12:30 PM

    • kure256
    • Not Ranked
    • Joined on 07-25-2007
    • Praha
    • Posts 7
    • Points 95

    deep validation

    Hello,
    Is it possible to execute deep validation in the NetTiers??

    I mean call Validate() method on parent entity. This entity will validate herself and automaticly all child entities. Than child entities will call Validate to their children. All broken rules will be stored in the BrokenList of parent entity.
    Is it possible? sequence of calling entities in the object tree is not important for me .

    I tried to play with validation rules, but unsuccessfully :(

    Thx kure256

    • Post Points: 35
  • 10-18-2007 1:50 PM In reply to

    • Polar
    • Top 100 Contributor
    • Joined on 09-04-2007
    • Posts 51
    • Points 935

    Re: deep validation

     As far as I know you have to do that yourself. Here is what I did:

    • Created IsDeepValid()
    • Created DeepValidate()
    • Created DeepBrokenRuleList()
    Now I know that IsDeepValid and DeepBrokenRuleList should be properties not methods, I needed something fast and this works for me. I'll probably change it later when I'm optimizing the code.  So pay attention when you use the base BrokenRuleList and IsValid as they are not methods.

    public void DeepValidate()
    {
        this.Validate();

        foreach (SomeObject1 item in this.SomeObject1Collection)
            item.Validate(); // or item.DeepValidate() if you have multiple levels

        foreach (SomeObject2 item in this.Some2ObjectCollection)
            item.Validate();
    }

    public bool IsDeepValid()
    {
        if (this.IsValid)
        {
            foreach (SomeObject1 item in this.SomeObject1Collection)
                if (!item.IsValid()) // or item.IsDeepValid()
                    return false;

           foreach (SomeObject2 item in this.Some2ObjectCollection)
                if (!item.IsValid()) // or item.IsDeepValid()
                    return false;
        }
        else
            return false;

        return true;
    }

    public Validation.BrokenRulesList DeepBrokenRulesList()
    {
        Validation.BrokenRulesList brokenRules = new Validation.BrokenRulesList();

        foreach (Validation.BrokenRule rule in this.BrokenRulesList)
            brokenRules.Add(rule);

        foreach (SomeObject1 item in this.SomeObject1Collection)
            foreach (Validation.BrokenRule rule in item.BrokenRulesList) // or item.DeepBrokenRulesList()
                brokenRules.Add(rule);

        foreach (SomeObject2 item in this.SomeObject2Collection)
            foreach (Validation.BrokenRule rule in item.BrokenRulesList)
                brokenRules.Add(rule);

        return brokenRules;
    }
    Filed under: ,
    • Post Points: 5
Page 1 of 1 (2 items) | RSS
Copyright © 2008 CodeSmith Tools, LLC
Powered by Community Server (Commercial Edition), by Telligent Systems