Tip: Create Custom Expressions on the base class

While developing OzCode, we work with multiple class types that represent a parsed C# code file: objects that represent things such as if statements, while loops, assignment expressions, and so forth. As you can imagine, the class hierarchy of these objects is quite complex and large – Underneath the base type there are dozens of derived classes, representing every single type of code construct that exists in C#.

When I initially started debugging, I discovered that the data I get when hovering over these objects wasn’t very useful to me:



This happened because the default ToString implementation of the object blurts out the structure of the parsed code, but what I really wanted to see is just the actual C# code that the object translates to.

And so, having already written a method called ToCSharpCode that takes in an object and returns the C# code it represents, I went on to add a custom expression:



The important thing to take away from the last screenshot is that I intentionally expanded the “base” nodes and chose to add the Custom Expression on the the highest base class in the class hierarchy that the custom expression is applicable to. This will ensure that my Custom Expression will appear not only on BinaryOperatorExpressions, but also onIfElseStatementsAssignmentExpressions, and so forth.

Next, I wrote my Custom Expression:



I used C#’s comment syntax (//) to give my custom expression a shorter name: “C#”.
And finally, I starred my Custom Expression, so it will always right next to the variable name:

Ozcode

Comments

Keep your code in good shape!

Subscribe to our blog and follow the latest news in the .NET debugging industry

Ready to Dive into Your Prod Code?

Easy debugging with full time-travel data

The Exception

A Quarterly Roundup

Subscribe to our quarterly newsletter and hear all about what’s happening around debugging with Ozcode

Share on facebook
Share on twitter

Recent Posts

Follow Us

Join Ozcode YouTube Channel

Let’s start debugging, it’s free!

Ozcode Logo

This website uses cookies to ensure you get the best experience on our website.