C#, Lokad.Shared: How to write custom rules to use with Enforce
<p>I am trying out the <a href="http://abdullin.com/shared-libraries/" rel="nofollow">Lokad Shared Libraries</a>, and it is looking very interesting and useful. I am able to use for example:</p>

<pre><code>Enforce.Arguments(() =&gt; arg1, () =&gt; arg2);
</code></pre>

<p>to throw an exception if arg1 or arg2 are null. But I would like to check if an IEnumerable has at least one item. I could use:</p>

<pre><code>Enforce.That(someSequence.Count() &gt; 0);
</code></pre>

<p>but that doesn't create a very useful error message. I have tried to look at the Sample code, etc., to find out how to write, and use, a custom rule. But I just can't seem to figure it out!</p>

<p>I have come this far (or short... to be more exact...):</p>

<ul>
<li>I should create a class to collect my rules in.</li>
<li>I think I need to somehow create a <code>Lokad.Rules.Rule&lt;T&gt;</code> delegate?</li>
<li>Which perhaps need to do something with an IScope, whatever that is....</li>
<li>And then somehow use that rule with one of the Enforce methods, although I am not quite sure how...</li>
</ul>

<p>So to sum up, this is what I want to end up with:</p>

<pre><code>public static void DoStuff&lt;T&gt;(this IEnumerable&lt;T&gt; subjects)
{
    Enforce.Argument(() =&gt; subjects);
    // Somehow in an equally smooth way check that 
    // subjects contains at least one element

    // Do stuff
}
</code></pre>

<p>Anyone able to help?</p>
