Is it a good idea to do checking preconditions and do some logic during implicit casting
<p>Full implementation is here <a href="https://gist.github.com/1306491" rel="nofollow">https://gist.github.com/1306491</a>
I'm using struct with implicit casting to implicitly convert to and from source type and describes check rule through generic parameters of the struct.
From my point of view it can reduce code repetition and can be read as an dsl.   </p>

<p>How to use:</p>

<pre><code>    static void Main(string[] args)
    {
        string s = Size(null);//result: argument exception
        Console.WriteLine(Lenght(null));//result 0
        DivByZero(0);// result: argument exception
        Log(5);//result: log 5 to console
        AddTenSymbols("");//result: if result string has lenght more than 10 then log result string/ 
        Console.ReadKey();
    }

    static Check&lt;string, IsNotNull&lt;string&gt;&gt; Size(Check&lt;object, IsNotNull&lt;object&gt;&gt; obj)
    {
        return obj.ToString();
    }

    static int Lenght(Check&lt;string, AndReplaceByEmptyIfNull&gt; str)
    {
        string stri = str;
        return stri.Length;
        //return ((string)str).Length;
    }

    static int DivByZero(Check&lt;int, If&lt;int, EqualsTo&lt;Zero&gt;, ThenThrowArgumentException&lt;int&gt;&gt;&gt; i)
    {
        return 1 / i;
    }

    static Check&lt;int, If&lt;int, BothTrue&lt;Not&lt;EqualsTo&lt;Zero&gt;&gt;, Not&lt;MoreThan&lt;Ten&gt;&gt;&gt;, ThenLog&lt;int&gt;&gt;&gt; Log(int i)
    {
        return i;
    }
    static Check&lt;string, If&lt;string, Member&lt;string, int, StringLenght, MoreThan&lt;Ten&gt;&gt;, ThenLog&lt;string&gt;&gt;&gt; AddTenSymbols(string s)
    {
        return s + "asffgsdfgd"; ;
    }
</code></pre>
