JOS.Enumeration - System.Text.Json support
The problem We want to use the same approach as we do when storing the enumeration class in the database, we only want to serialize the actual value of the enumeration. We also want to be able to only...
View ArticleJOS.Enumeration - Now using source generators
Lately I've played around a bit with source generators. I wanted to see if I could improve the experience of using my JOS.Enumeration project. "Old" implementation When creating your own Enumeration...
View ArticleUsing records when implementing the builder pattern in C#
Photo by Vitolda Klein I tend to use the builder pattern quite a bit when writing my tests. It's really convinient to create a builder and have a fluent interface when creating some test data. We'll be...
View ArticleMy take on the Result class in C#
Photo by Agence Olloweb Introduction Don't use exceptions for flow control! This is a quote I stumbled on quite a bit during my first years as a programmer. Let's imagine the following scenario: We...
View ArticleJOS.Enumeration - System.Text.Json support
The problem We want to use the same approach as we do when storing the enumeration class in the database, we only want to serialize the actual value of the enumeration. We also want to be able to only...
View ArticleJOS.Enumeration - Now using source generators
Lately I've played around a bit with source generators. I wanted to see if I could improve the experience of using my JOS.Enumeration project. "Old" implementation When creating your own Enumeration...
View ArticleUsing records when implementing the builder pattern in C#
Photo by Vitolda Klein I tend to use the builder pattern quite a bit when writing my tests. It's really convinient to create a builder and have a fluent interface when creating some test data. We'll be...
View ArticleMy take on the Result class in C#
Photo by Agence Olloweb Introduction Don't use exceptions for flow control! This is a quote I stumbled on quite a bit during my first years as a programmer. Let's imagine the following scenario: We...
View ArticleJOS.Enumeration - System.Text.Json support
The problem We want to use the same approach as we do when storing the enumeration class in the database, we only want to serialize the actual value of the enumeration. We also want to be able to only...
View ArticleUsing records when implementing the builder pattern in C#
Photo by Vitolda Klein I tend to use the builder pattern quite a bit when writing my tests. It's really convinient to create a builder and have a fluent interface when creating some test data. We'll be...
View ArticleJOS.Enumeration - System.Text.Json support
The problem We want to use the same approach as we do when storing the enumeration class in the database, we only want to serialize the actual value of the enumeration. We also want to be able to only...
View ArticleJOS.Enumeration - Now using source generators
Lately I've played around a bit with source generators. I wanted to see if I could improve the experience of using my JOS.Enumeration project. "Old" implementation When creating your own Enumeration...
View ArticleEF Core - Add a test to ensure that you don't forget to add new migrations
Scenario We want the Hamburger enumeration class to always be up to date in our database. We configure our DbContext like this: public class MyDbContext : DbContext { public DbSet<Hamburger>...
View ArticleC# - Tips and Tricks 01 - Covariant return types
The problem We have the following code: public abstract class MessageHandler { public abstract Message Poll(); } public abstract class Message { protected Message(string id, string correlationId,...
View ArticleEF Core - Add a test to ensure that you don't forget to add new migrations
Scenario We want the Hamburger enumeration class to always be up to date in our database. We configure our DbContext like this: public class MyDbContext : DbContext { public DbSet<Hamburger>...
View ArticleCreating a Roslyn Analyzer to ensure that no duplicate values are added at...
Intro We have the following enumeration class. public partial class Hamburger : IEnumeration<Hamburger> { public static readonly Hamburger Cheeseburger = new (1, "Cheeseburger"); public static...
View ArticleC# - Tips and Tricks 01 - Covariant return types
The problem We have the following code: public abstract class MessageHandler { public abstract Message Poll(); } public abstract class Message { protected Message(string id, string correlationId,...
View ArticleC# - Tips and Tricks 02 - Named tuples
The problem We have the following code that returns a tuple. public class UserService { public (string, string) GetUser() { var firstName = "Josef"; var country = "Sweden"; return (firstName, country);...
View ArticleEF Core - Add a test to ensure that you don't forget to add new migrations
Scenario We want the Hamburger enumeration class to always be up to date in our database. We configure our DbContext like this: public class MyDbContext : DbContext { public DbSet<Hamburger>...
View ArticleCreating a Roslyn Analyzer to ensure that no duplicate values are added at...
Intro We have the following enumeration class. public partial class Hamburger : IEnumeration<Hamburger> { public static readonly Hamburger Cheeseburger = new (1, "Cheeseburger"); public static...
View Article