On the second day of Christmas, 2sxc Razor can use C# v8!
Goodies Galore: C# 8 is sooo much nicer
By default, Dnn only provides C# 5, so the code you write in Razor and ascx files is kind of clunky. Here are some things you can't do in existing solutions:
- var name = something?.Name; // null conditional operator
- name ??= "unknown"; // null coalescing operator
- public Name => "iJungleboy"; // arrow properties
- var x = (true, "Daniel", 7); // tuples
...and way more. With C# 7.3 most of this is possible, and C# 8 is even greater (eg. the ??= requires C# 8).
Does C# 8 work in .net Framework?
Absolutely. We from the 2sxc dev team migrated most of our code to C# 12 recently, and it worked flawlesly even for .net 4.7.2. At runtime we'll probably need to stick to C# 8 for a while, but who knows 🤷♂️. Check out this video by Nick explaining why this actually works:
Background: Dnn uses C# v5 by Default
Out of the box Dnn has C# 5 built in, which is sooo 2012 🥱.
But Dnn actually had an optional library called CodeDom, which installed the Roslyn compiler and with it C# 6, 7.3 or even C# 8. But this has been a secret gem since forever!
Dnn 10 will Auto-Install C# 7.3 or C# 8
By default, the next big version of Dnn will automatically install the CodeDom 3.6 which supports C# 8. The current install seems to only activate C# 7.3, but we hope that Dnn will also toggle C# 8 to be the next default.
But why wait?
We've done extensive testing and discovered that we can activate C# 8 on Dnn 9.6.1 or later without any problems!
2sxc 17 will Require CodeDom/Roslyn to be Installed
Since the code we can write is so much nicer (and because we have some crazy features coming up) we decided it's time to move forward. 2sxc 17 will therefor require C# 8 to be installed, and guide you through the process.
➡️ Here are the instructions if you want a head start
Note that the Dnn installation will only activate C# 7.3, but 2sxc will run the compiler using C# 8. Only 2sxc-Razor will support C# 8.
Merry X-Mas for Day 2
iJungleboy