c#

Initialising a collection from another collection

Here's a handy trick I discovered whilst fixing a bug. You can initialise a collection from another collection and add new items to it as follows:

Note that the collection initialiser on AllFoo runs before the constructor, so the Foo created with constructor parameter 4 will appear first in AllFoo, followed by everything in BaseCollectionOfFoo in the expected order.

Pretty-printing JSON with Json.NET

I was struggling to find a way to pretty-print a JSON string in .NET. I already have the excellent Json.NET package available and after a bit of hunting, I came up with this:

It wasn't obvious how to do this, for some reason - I spent a while investigating the JsonReader and JsonWriter classes to no avail.

Hope this helps you too!

Project Roslyn: .NET's Compiler as a Service

I spent some of this evening watching the video from Microsoft Research on their Project Roslyn, the codename for the Compiler-as-a-Service functionality they're developing for .NET vFuture.

The most interesting parts of the talk for me were:

Subscribe to RSS - c#