C#

NuGet Central Package Management (CPM)

Have you been working in a large code base and feel the pain of updating NuGet package version across many projects? Not only is it painful to update all the version in every projects, it is especially painful when you try to review a pull request with 99 files updating the .csproj and only 3 […]

Sam Lau 
C#

Benchmark .NET regular expression source generators

If you worked with regular expression and have upgraded to .NET 7 or newer, you may see a warning SYSLIB1045: Use GeneratedRegexAttribute to generate the regular expression implementation at compile time. to alert you that you can use the new regular expression source generation. But is it really better? I have done a benchmark to […]

Sam Lau 
C#

launchSettings.json not used by Rider

I am switching to Rider from Visual Studio as my IDE recently and I have faced this situation where Rider is not picking up environment variable from launchSettings.json. I would like to share what I learnt. Issue I realized something was wrong while debugging my app where my configurations from appsettings.Development.json were not being picked […]

Sam Lau 
C#

Why you should use early return in C#?

Today, I am going to share a simple technique that can improve the readability of your code: early return pattern. What is early return? In a method, there are usually the happy path (main logic) and the unhappy path (invalid input, invalid operation, etc.). Early return pattern is writing code such that when an unhappy […]

Sam Lau 
C#

Explain Dependency Injection Like I am Five

If you read posts about .NET or Microsoft’s documentations, you see the parse “dependency injection” (DI) a lot. Everyone say it is good practice and you should do it but what exactly is DI? Today, I will try to explain dependency injection like you are five. Dependency Inversion Before talking about dependency injection, let’s talk […]

Sam Lau