Jun 02

Interactive coding in Visual Studio with Alive

Tags: , , , , Comments Off on Interactive coding in Visual Studio with Alive

If you like NCrunch, you should take a look at the Visual Studio plugin Alive. I stumbled upon this tool while researching for my previous post about C# code generation.

Just like NCrunch, it executes your code while you type. But instead of test outcomes, it focusses on the details of the code execution and provides invaluable insight into the contents of variables and even the control flow as you type. You can even drag a slider to see different iterations in loops. All you need is a starting point like a static method, a test method or any method where the parent type can be instantiated with some generic defaults.

This short video (~6 minutes) gives a great first impression so far:

Continue reading »

Jun 01

How to generate C# code in 2016

Tags: , , , , , Comments Off on How to generate C# code in 2016

Today I wanted to generate a bit of rather trivial C# code to provide a convenient facade to an internal library. After creating a T4 template, loading the required assembly and adding some namespace imports, I found it rather inefficient to write code in that simple text editor without IntelliSense. So of course, there is always the option to write a code generator class with a method that returns a string. The T4 template can instantiate that class, call the method and emit the value directly:

<#= new CodeGenerator().Generate() #>

Next comes the question of how to implement the generator. StringBuilder? Come on, there must be a better way. I checked in another library that I knew was using code generation. Then I saw that the library was using CodeDOM. For my simple needs, I decided that this would be sufficient for the time being (and efficient, since I didn’t want to spend too much time there).

But then I started to wonder. Will CodeDOM still work with the new .NET Core?

Continue reading »