C# - custom explicit conversion with checked/unchecked operator
<p>I'm learning to write custom type conversions in C# and I have a question I can't manage to resolve with Google / MSDN / earlier posted SO items.</p>

<p>Normally, a C# program that narrows a numeric type does that via unchecked explicit conversion, e.g.:</p>

<pre><code>int i = 256;
byte b = (byte)i; // b == 0
</code></pre>

<p>however, the following will give an overflow exception:</p>

<pre><code>byte b = checked((byte)i);
</code></pre>

<p>My question is as follows: is the behavior of the checked / unchecked keyword implementable in an custom type conversion, e.g.:</p>

<pre><code>class Foo {
  public static explicit operator int(Foo bar) {
    if (checked)
      throw someEception
    else
      return some Foo to int conversion
  }
}
</code></pre>

<p>Of course, the code above is not the answer, but does anyone know if something like this is possible?</p>
