Tag Archives: C#

[c#] Extending Enums on .NET

One of these days I had the need to create and extensible enum. Extensible in a way that allows people to add items to it, but outside the assembly where the enum is declared.

The short answer to this is that enums are not extensible Triste

It become clear that I would need to find a workaround. Since we had some legacy code already working, it was necessary to keep the normal usage of the enum (i.e. switch – case).

The following solution may not be the best one, but it’s working good, allowing the extension of the enum and still preserve their traditional usage on the switch-case blocks.

Note: the following code is used to “replace” enums deriving from INT. Deriving from other datatype involves changing the operators.


Continue reading “ Extending Enums on .NET” »

Using an enum on a FluentNHibernate mapping [C#]

One of these days I needed to map a C# class to a database table using FluentNHibernate. So far so good….
But then I got stuck as one the class properties was an enum.

As it turns out, there is no automatic mapping to enums.

The solution is to use a Custom Type and let FluentNHibernate know that that specific property has a custom type.
How can that be achieved?

Continue reading “Using an enum on a FluentNHibernate mapping [C#]” »