Skip to content

Commit

Permalink
Nova rotina para retornar o EnumValue pelo DefaultValue
Browse files Browse the repository at this point in the history
  • Loading branch information
adrianotrentim committed May 15, 2024
1 parent 8c3be02 commit 70dc642
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/FiscalBr.Common/Helpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public static T GetEnumMaxValue<T>() where T : Enum
return Enum.GetValues(typeof(T)).Cast<T>().Max();
}

public static int[] GetEnumValues<T>() where T : Enum
public static int[] GetEnumValues<T>() where T : Enum
{
return (int[])Enum.GetValues(typeof(T));
}
Expand Down Expand Up @@ -117,6 +117,17 @@ public static TEnum ToEnum<TEnum>(this string @this, TEnum defaultValue)

return defaultValue;
}

public static TEnum ToEnumByDefaultValue<TEnum>(this string @this) where TEnum : Enum
{
var enumItens = Enum.GetValues(typeof(TEnum));

foreach (var item in enumItens)
if (((TEnum)item).ToDefaultValue() == @this)
return (TEnum)item;

return default(TEnum);
}
}

public static class TypeHelpers
Expand Down

0 comments on commit 70dc642

Please sign in to comment.