Posts about the C# language itself, including use, abuse and features.

Introducing the Priority Queue

Saturday, October 20 2018 priority-queues csharp

Recently, while working on a personal project, I needed a priority queue. Instead of slamming all of the items into a sorted list and making do, I decided to do the job properly and write a proper abstraction. To keep things interesting, it was an immutable implementation.

Read more »

A better approach to reflection

Saturday, October 13 2018 csharp

One of the recurring themes on this blog is the idea of making the computer work harder, not the user or the developer. I discovered recently that there was an easier and faster reflection technique than the one I was using - the technique that I’d been using for most of a decade!

Read more »

Avoiding Magic Strings

Saturday, October 06 2018 validation csharp

Building on the infrastructure defined last time, let’s look at how we can avoid the use of magic strings when working with metadata.

Read more »

Capturing Validation Metadata

Saturday, September 29 2018 validation csharp

In the last post we showed an api for how we can inject additional metadata into our validation results. The implementation is relatively straightforward - but there are a few moving parts that need to mesh together appropriately.

Read more »

Modelling Validation Metadata

Saturday, September 22 2018 validation csharp

Given our requirement of supporting arbitrary metadata on our validation results, how should we modify the semantic types we’ve already created?

Read more »

Validation Metadata

Saturday, September 15 2018 validation csharp

It’s a common requirement for validation messages to be tagged with additional metadata. We might want to indicate which data entry field is the one with a problem, or perhaps provide a tag for machine consumption that identifies which specific problem was encountered.

Read more »

Extending validation with warnings

Saturday, September 08 2018 validation csharp

If we cast back our thoughts back to the start of this series, one of the limitations of using string to return each of our errors was that every message has to be an error. What do we do if we want to support another kind of message?

Read more »

Validation recap

Saturday, August 25 2018 validation csharp

Let’s recap what we’ve achieved so far with our semantic types for validation. We’ve created a handful of types that work together to give a good model for capturing and processing object validation. The model starts with the base class ValidationResult and its subclasses:

Read more »

Equality of validation

Saturday, August 18 2018 validation csharp

While writing tests for the code presented in the last couple of weeks, I discovered a notable bug caused by an ommission in the code. If you’re a regular reader of this blog, you may have already spotted what was left out.

Read more »

Short-circuiting validation

Saturday, August 11 2018 validation csharp

Following on from last week’s introduction of the plus operator, a friend of mine challenged me to consider an alternative operator for combining validation results: &&

Read more »

Aggregation of validation

Saturday, August 04 2018 validation csharp

We’ve created the basics of our validation library, but we haven’t yet addressed the problem of aggregation. How do we make it easy for our consumers to combine multiple validation results together into one. Ideally, we want this to be so simple that they don’t have to think about it at all.

Read more »

Recovery of validation types

Saturday, July 28 2018 validation csharp

As alluded in the prior post, all of our return types so far have been ValidationResult - but our consumers will need to know whether they have a success or an error in order to make decisions.

Read more »

Basic validation

Saturday, July 21 2018 validation csharp

To recap from last time, we want to create a simple library that allows us to express validation in a straightforward way, allowing us to concentrate on the rules we’re checking, not the boilerplate needed to make it work.

Read more »

Why we need better validation

Saturday, July 07 2018 validation csharp

The state of validation in C# leaves something to be desired. Recently I was writing some code in the same old classic styles and the frustration got to me - surely there must be a better approach that doesn’t involve great lists of strings, the use of exceptions for flow control, and brittle unit tests.

Read more »

Older posts

A question of struct performance  30 Jun 2018
Equality has Symmetry  17 Mar 2018
Type Miscellany  05 Mar 2017
Testing Immutable Types  25 Feb 2017
Factory Methods  18 Feb 2017
Queue Concatenation  11 Feb 2017
Complex Queues  04 Feb 2017
The Problem with the Simple Queue  28 Jan 2017
Enumeration of Queues  21 Jan 2017
Reversing Stacks  14 Jan 2017
Simple Queues  07 Jan 2017
Queues  30 Dec 2016
Stacks Miscellany  22 Dec 2016
Stack Equality  09 Dec 2016
Enumerating Stacks  03 Dec 2016
Stacks  19 Nov 2016
When (not) to use Var  16 Jul 2016
Semantic Types Redux  05 Jun 2016
Semantic Types in C#6  27 May 2016
Property Enhancements for C#  20 Dec 2015
Language Extensions for C#  19 May 2014
When should methods be Static?  09 Oct 2012
Of Method Naming and more  29 Sep 2012
Someone needs an intervention  16 Dec 2011
CallerInfo in C# 5  08 Dec 2011
Regions in C#  16 May 2011
Lambda expressions and Block syntax  15 Apr 2011
Parameter Attributes and more  05 Feb 2011
Elegant.Data  19 Oct 2010
Doing less with LINQ  30 Jun 2010
WCF and IList  28 May 2010
Specialist Classes  22 May 2010
Attack of the Lazy Coder  20 May 2010
A Discovery in Linq: Lookup  11 Feb 2010
Co- and Contra-Variance in .NET 3.5  15 Sep 2009
When to use Var  26 Mar 2009
Struct Weirdness  11 Feb 2009
Contravariance and Covariance at last  29 Oct 2008
Spec#  30 Apr 2008
Lambda Events  22 Mar 2008
No longer the C# we knew  21 Mar 2008
Rare C#  12 May 2007
Generics in .Net  28 Jan 2004