I'm at a point in my custom view engine that I want things to be a bit cleaner. One of the ugliest parts I have so far is iif
type functionality. It ends up looking like this:
{= CssClass==null ? "" : "class=\""+CssClass+"\"" =}
which compiles(it's a T4 template, so it just generates C# code) to the equivalent of
Write(CssClass==null ? "" : "class=\""+CssClass+"\"");
One way of shortening this I can think of is the ??
operator, but that doesn't help when you have something like Comments.Count==0
I have mostly full control over the generated C# code and what the syntax looks like in a view, so what would be a better way to do this in my design? I'm aiming for something more readable, but also fairly concise. So what syntax modifications should I allow in my view engine to make it looks better?