Skip to content

Add non-generic EnumDehumanizeExtensions.DehumanizeTo #92

Closed
@JeremyThomas

Description

@JeremyThomas

I could use a non-generic EnumDehumanizeExtensions.DehumanizeTo for when the enum type isn't known at compile time.

I wrote my own which I use in my HumanizedEnumConverter:
https://rapiddevbookcode.codeplex.com/SourceControl/latest#LLBL Pro v4.1/AW.Helper/TypeConverters/HumanizedEnumConverter.cs

e.g.

    private static Enum DehumanizeTo(string input, Type enumType)
    {
      var values = Enum.GetValues(enumType);
      foreach (var value in values)
      {
        var enumValue = value as Enum;
        if (enumValue == null)
          return null;
        if (string.Equals(enumValue.Humanize(), input, StringComparison.OrdinalIgnoreCase))
          return enumValue;
      }
      return null;
    }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions