Extension methods on Enums?

by Jun 7, 2024

Extension methods on Enums?

Do you sometimes feel restricted by the Enum type in C#? You want to give it a little bit extra behavior by adding a method?

Currently you can’t add extension methods to Enums.

Some other programming languages do offer this capability which gives Enum more power and usefulness.

In C# 13 a new type will be added: Extension types.

They look very promising. It’s basically a complete redesign of Extension methods. You can apply the to any type in C#! Beside methods, properties and other members are also possible. And they can be instance or static!

They bring in more the functional way of writing code into C#. Just like in Go, you can create a type that just represents data and then use the new Extension type to decorate it with functions.

You can also create new ‘alias’ types based on an existing type with additional behavior, just like in F#. A better way then using inheritance in OOP.

A new interesting way to program is being added to C#. What do you think?


Subscribe to
The Daily Friction

A daily newsletter on automation and eliminating friction

Related Content

SpecFlow: Great concept, flawed execution.

SpecFlow: Great concept, flawed execution. SpecFlow, a BDD framework designed to make writing scenarios a breeze for requirement analysts. The problem: It falls short of its promise. ❌ The reality? Analysts rarely, if ever, write the specs themselves. Instead,...

read more

What if…? Production has a Staging slot.

What if...? Production has a Staging slot. Staging or QA environment needs to be the same or as close to production as it can be. Preferably, you want to restore a recent backup 💾 from Production as Staging and then deploy your changes 🔄. Kudos 👏 if you've fully...

read more

UUID v7 coming in .NET 9

UUID v7 coming in .NET 9 For those that didn't know, you can create Guids in different ways (algorithms). System.Guid supports UUID v4 out-of-the-box, the most used version. UUID v7 is now added, which creates Guids based on the current time. This means Guids can be...

read more