Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add non-generic EnumDehumanizeExtensions.DehumanizeTo #92

Closed
JeremyThomas opened this issue Feb 17, 2014 · 1 comment
Closed

Add non-generic EnumDehumanizeExtensions.DehumanizeTo #92

JeremyThomas opened this issue Feb 17, 2014 · 1 comment

Comments

@JeremyThomas
Copy link

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;
    }
@MehdiK
Copy link
Member

MehdiK commented Feb 17, 2014

Thanks - yeah I think that could be useful at times.

I would appreciate if you could please review #93 for this.

MehdiK added a commit that referenced this issue Feb 18, 2014
added non-generic DehumanizeTo - addresses #92
@MehdiK MehdiK closed this as completed Mar 2, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants