Softwire Blog


Friday Lunch and Learns: C# and .NET


26 April 2013, by

Every Friday lunchtime at Softwire we all get lured into a meeting room with the promise of free food, and one of our colleagues gives a talk on something they’ve been working on recently.

We filmed this talk on C# and .NET, by Sam Carr, so that others can enjoy it too.

Streams, Readers and Writers in C#


8 February 2013, by

I have recently started to hold weekly sessions in which I attempt to explain a subject that I think I know something about, to a small group of people who think they don’t but want to. The first one was very successful – at least if you judge by the amount that I learnt in the process!

The topic of the session was Streams in C#. But it rapidly transpired that the problem wasn’t so much Streams as “Streams and all the other stuff you tend to use with them”, so we spent a lot of time learning about the various Writer classes in the C# base class library. The number one conclusion was that you really need to Just Know which thing to use in which situation, and this blog post attempts to summarise the key things everyone will have forgotten by the time they next use a Stream or something of its ilk.

I’ll start with a little background, and then move on to a ready reference.

(more…)

Grouping with LINQ


20 August 2012, by

previous article in series

When I was first starting out with LINQ, the method I had most trouble getting my head round was GroupBy. So I wanted to finish this series of posts with a quick how-to on grouping, in case others find the same problem.

In SQL, GROUP BY seems so straightforward. Somehow in LINQ it seems to contrive to cause problems though. But it’s easy when you know how.

(more…)

Don’t be too lazy – LINQ’s lazy evaluation gotchas


13 August 2012, by

previous article in series

Having discussed how to take advantage of lazy evaluation in LINQ, it only seems right to discuss some of the surprises this might cause you. I’ve picked out a few examples from my own experience of where understanding what’s going on behind the scenes is important to avoid falling into a trap.

(more…)

Lazy LINQing


6 August 2012, by

previous article in series

This post looks at one reasonably important aspect of how LINQ works under the hood – lazy evaluation.

(more…)

Simplify with LINQ


30 July 2012, by

Using LINQ to simplify your code

previous article in series

LINQ is all about manipulating data. But actually, so is a remarkably large amount of programming. We’ve already looked at some things you can do with your list of beers using LINQ, but actually if you go back to the example I used to introduce generics, that’s all about manipulating data too:

(more…)

An introduction to LINQ


23 July 2012, by

previous article in series

This series of posts is about Language Integrated Query (LINQ, pronounced “link”) – a set of libraries providing a means of querying data in C#. It is intended very much as a beginner’s guide, although those who have a basic knowledge of LINQ but don’t have a full understanding of its principles might still find some points of interest.

(more…)

Generic collections in C#


16 July 2012, by

Over the next few weeks I’ll be publishing a short series of posts introducing Language Integrated Query (LINQ). However to use LINQ well it’s important to have a basic understanding of Generics, so my first post covers this topic. For nostalgia value, I’ve included a little bit of history from the heady days of .NET 1.1, and some advice for anyone who’s coming back to .NET programming having not used it since those days.

(more…)

Code Generation in .NET with the Roslyn CTP (Part 3)


12 July 2012, by

previous article in series

Visual Studio custom toolThis post is the third in a series on code generation on the .NET platform. In this post, we will look at how to package a code generator as a Visual Studio extension, and how best to share a single library between multiple extensions.

(more…)

Code Generation in .NET with the Roslyn CTP (Part 2)


5 July 2012, by

previous article in series

Visual Studio custom tool

This post is the second in a series on code generation on the .NET platform. In this post, we will take a closer look at Microsoft’s Community Technology Preview of ‘Roslyn’. In brief, this is a C# compiler implemented in managed code that exposes an API to let you hook into the compilation process.

Recap

In the previous post, I introduced Roslyn as an interesting tool for code generation, in particular when generating source code from other source code. Roslyn is especially appealing for this purpose because it provides a strongly-typed model for working with source code and (unlike most code generation approaches) allows you to use the same model for both input and output.

One of the common drawbacks of most other options for code generation (as discussed in the previous post) is the need to translate from one model to another and how clumsy this can be, particularly when you want to carry across some elements of the input source code without changing them. A detailed example of when you might need to do this is discussed in the appendix at the end of this post. (more…)