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 _______________________________________________ Mono-devel-list mailing list Mono-devel-list@lists.ximian.com http://lists.ximian.com/mailman/listinfo/mono-devel-list