Friendly Enum Labels C# Extension

Here's a nice trick I recently found. Let's say you have an enum and want to render the enum choices to a dropdown list. But the enum values don't permit spaces, so they won't render in an easy-to-read fashion. This tip creates an extension for enums that allows for a string value decorator on each enum choice. The decorator permits a friendly name to be specified. The extension adds a method to all enums that make it easy to pull the friendly name value. Start by setting up an enum class like this: namespace CommerceBuilder.Products { public enum DigitalAssetType { ...

Oct 12, 2020 READ MORE