Skip to content

Commit b1670cd

Browse files
committed
Support for enums of any available enum type
1 parent 7689170 commit b1670cd

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

RestSharp/Extensions/ReflectionExtensions.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,10 +98,10 @@ public static object FindEnumValue(this Type type, string value, CultureInfo cul
9898

9999
if (ret == null)
100100
{
101-
int enumValueAsInt;
102-
if (Int32.TryParse(value, out enumValueAsInt) && Enum.IsDefined(type, enumValueAsInt))
101+
var enumValueAsUnderlyingType = Convert.ChangeType(value, Enum.GetUnderlyingType(type), culture);
102+
if (enumValueAsUnderlyingType != null && Enum.IsDefined(type, enumValueAsUnderlyingType))
103103
{
104-
ret = (Enum) Enum.ToObject(type, enumValueAsInt);
104+
ret = (Enum) Enum.ToObject(type, enumValueAsUnderlyingType);
105105
}
106106
}
107107

0 commit comments

Comments
 (0)