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

Scrum conceals bad teams.

Scrum conceals bad teams. Far too often, we confuse Scrum with a magic wand that transforms any team into a high-performing 'dream team'. It's tempting to believe that the sprint system, with its regular completion and initiation of tasks, gives us an agile and...

read more

🚀 Process Automations in Microsoft Loop!

🚀 Process Automations in Microsoft Loop! Now you can create Power Automate-backed rules to streamline repetitive tasks in your Loop table. See https://insider.microsoft365.com/en-us/blog/streamline-your-workflow-with-automation-in-microsoft-loop Loop is slowly...

read more

You don’t control the truth in Production!

You don't control the truth in Production! Now a days multiple teams/projects are working on the same Dataverse production environment. So thinking you can manage the complete production truth in your ALM pipeline is strange. Not every environment is 💯 equal to...

read more
Share This