Skip to content

Instantly share code, notes, and snippets.

@AThraen
Created December 2, 2022 15:33
Show Gist options
  • Select an option

  • Save AThraen/f40d9e09c829f8e33c08786b68f8fd5d to your computer and use it in GitHub Desktop.

Select an option

Save AThraen/f40d9e09c829f8e33c08786b68f8fd5d to your computer and use it in GitHub Desktop.
Optimizely/Episerver CMS Generic Enum Selection Factory
public class GenericEnumSelectionFactory<TEnum> : EnumSelectionFactory where TEnum : Enum
{
protected override Type EnumType => typeof(TEnum);
public GenericEnumSelectionFactory() : this(LocalizationService.Current)
{
}
public GenericEnumSelectionFactory(LocalizationService localization) : base(localization)
{
}
protected override string GetStringForEnumValue(int value) =>
this.LocalizationService.GetString("/Enums/" + nameof(TEnum) + "/" + Enum.GetNames(EnumType)[value], Enum.GetNames(EnumType)[value]);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment