[Mono-dev] gmcs and The Future

Jonathan Pryor jonpryor at vt.edu
Thu Feb 5 12:19:41 EST 2009

On Thu, 2009-02-05 at 12:10 -0500, Avery Pennarun wrote:
> (The reason I use cpp, incidentally, is so I can implement C-style
> assert() and check() macros that actually print the condition being
> tested as part of the assertion message.  There seems to be no other
> way to do this in C#, which is too bad.)

There is now.  It's not the most performant technique around, but your
Assert() or Check() methods could take an Expression<T>.  The
Expression<T> can then be converted into a string for diagnostic
messages, and converted into a delegate for the actual condition check,

	static void Assert<T>(T value, Expression<Func<T, bool>> e)
		Func<T,bool> d = e.Compile();
		if (!d (value)) {
			// Convert `e' to a string and log

	// ...

	Assert(self, v => v != null);

All that's really needed for this is a way to convert the Expression
into a usable string, which may already exist for all I know...

 - Jon

More information about the Mono-devel-list mailing list