[Mono-dev] gmcs and The Future
Jonathan Pryor
jonpryor at vt.edu
Thu Feb 5 15:24:51 EST 2009
On Thu, 2009-02-05 at 18:54 +0000, Marek Safar wrote:
> Here is slightly simplified version
>
> [Conditional("DEBUG")]
> static void Assert (Expression<Func<bool>> e)
> {
> var d = e.Compile ();
> if (!d ()) {
> Console.WriteLine (((LambdaExpression)e).Body.ToString ());
> }
> }
>
> public static void Main ()
> {
> object self = null;
> Assert (() => self != null);
> }
Nice. I didn't know that there was existing support already.
There's one problem, though: this prints out "(null != null)", which
isn't terribly helpful. :-)
This is one advantage to the parameter based version:
[Conditional("DEBUG")]
static void Assert<T>(T value, Expression<Func<T,bool>> e)
{
if (!d.Compile() (value))
Console.WriteLine(
((LambdaExpression)e).Body.ToString ());
}
When it fails, it prints out "(v != null)" instead, which is somewhat
more useful (except that `v' won't be something the user knows about).
- Jon
More information about the Mono-devel-list
mailing list