Why we need semantic types for effective validation in C#.
Why we need semantic types for effective validation in C#.
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.
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.
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.
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.
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: &&
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.
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:
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?
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.
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?
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.
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.