Programming

Removing Special Characters and Diacritic Marks in C#

Posted on

I did this trick in JavaScript to remove diacritic marks a while back and the need to perform a similar transformation in C# came up this week. The following method simplifies strings such as “façade” into simple string like “façade”. private static string Simplify(string input) { string normalizedString = input.Normalize(NormalizationForm.FormD); StringBuilder stringBuilder = new StringBuilder(); […]

Programming

Linq Style Mapping for Single Objects

Posted on

Linq is not just the go-to .NET library for handling IEnumerable data sources, it’s the inspiration for many successful and unsucessful attempts to reproduce the style in other languages. When you have a class full of Linq and you find yourself wanting to simply map a single object to something else, you’ll find yourself writing […]

Programming

C# Implicitly Scoped Using Statements

Posted on

This is a little gold nugget that is coming in C# 8 – implicitly scoped using statements. On a simple level, it means that when you consume an IDisposable class your previously explicitly scoped using statements: using (var connection = GetConnection()) { // Use the connection, it will be disposed of at the end } […]

Programming

C# Interfaces: Default Implementations

Posted on

The C# 8.0 announcement included a note on default implementations of interface members. If you’ve been programming for long enough, this might make you a little nervous at first thanks to the hangovers of multiple inheritance. Before you chuck out this idea, though, let’s look at it from a different perspective. I’m going to talk […]