I'm developing for Unity3D using C#, and decided it would be useful to have an assert function. (In Unity3D, System.Diagnostics.Debug.Assertexists, but does nothing.)

As a developer that works primarily in C++, I'm used to assert messages that contain the asserted expression by way of the preprocessor stringizing operator. That is, given a failed assertion of the form ASSERT(x > 0, "x should not be zero."), the message displayed at runtime message can include the text "x > 0". I'd like to be able to do the same in C#.

I'm aware of ConditionalAttribute and DebuggerHiddenAttribute, and am using both (although the latter seems to be ignored by the custom build of MonoDevelop bundled with Unity). While searching for a solution to this problem, I came across three attributes in the System.Runtime.CompilerServices namespace that seem related to what I'm trying to do: CallerFilePathAttribute, CallerLineNumberAttribute, and CallerMemberNameAttribute. (In my implementation, I use System.Diagnostics.StackTrace with fNeedFileInfo == true instead.)

I'm wondering if there is perhaps any reflection magic (seems unlikely) or attribute magic (seems slightly more likely) that can help me achieve the same functionality as I'm used to in C++.