Validation Result Practies. Boolean or Count?
<p>Over a few years, I have have written a few validation classes and have always wonder what people thinks is the best way of handling them.</p>

<p>I've seen and done each of the following and am curious to your know opinions and why.</p>

<p><strong>Scenario 1, Message Counting</strong></p>

<pre><code>class ValidationClass1
{
    public List&lt;string&gt; ValidationMessage { get; set; }

    public void Validate(x)
    {
        // pseudo-code
        if (!rule_logic1)
        {
            ValidationMessage.Add("Error in logic 1");
        }
        if (!rule_logic2)
        {
            ValidationMessage.Add("Error in logic 2");
        }
    }
}
</code></pre>

<p><strong>Scenario 2, Returning an Object or Tuple</strong></p>

<pre><code>class ValidationClass
{

    public Tuple&lt;bool, List&lt;string&gt;&gt; Validate(x)
    {
        List&lt;string&gt; ValidationMessage = new List&lt;string&gt;();
        bool passed = true;

        // pseudo-code
        if (!rule_logic1)
        {
            ValidationMessage.Add("Error in logic 1");
            passed = false;
        }
        if (!rule_logic2)
        {
            ValidationMessage.Add("Error in logic 2");
            passed = false;
        }

        return new Tuple&lt;bool, List&lt;string&gt;&gt;(passed, ValidationMessage);
    }

}
</code></pre>

<p>In Scenario 1, the ValidationMessage list could be the return type as well.  Regardless, calling code would have to check the count property of the list to see if the data passed or not.  If it was only a singular rule, the returning string length would need to be checked via string.IsNullOrEmpty(x).</p>

<p>In Scenario 2, a custom object or tuple would be the return type so that the calling code would have to have knowledge of the returning code and evaluate a boolean property to see if it passed and then the validation messages.</p>

<p>So, in your opinion, which way do you prefer or if you have a different preference, I'd be curious to hear that as well.</p>

<p>Thanks</p>
