Custom Debug Visualizer - For C# Stack

Creating Custom Debug Visualizer in C#

Debug Visualizers are visual studio IDE’s debugging component. These components represent the variables and class objects in meaningful form so that it can be easily visualised. Say; for example, you have class ABC to store the “Passport Size” photo of a person and using the visualizer you can see the photo of the person while debugging the object of ABC. In this example, we will create our own visualizer to see the Stack data structure. You can use the technique explained here with any objects.

The Item marked as 1 show five elements pushed into the Stack object of the Dot Net Framework. Item marked as two shows the Visual studio debugger showing the Visualizer written by us. If we write multiple visualizers for the same Stack object, C# debugger lists them all here. Moreover, we can mention the default one by placing the check mark. Clicking the lens icon invokes that default visualizer. The item marked as three shows the simple stack debug visualizer which lists all the current items in the stack. Left is the Top of the Stack and right is the bottom of the stack.