Skip to content

Commit cead3ac

Browse files
committed
Factor out IsEnumType method
1 parent d7e5664 commit cead3ac

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

crypto/src/util/Enums.cs

+11-10
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,7 @@ internal abstract class Enums
1414
{
1515
internal static Enum GetEnumValue(System.Type enumType, string s)
1616
{
17-
#if NEW_REFLECTION
18-
if (!enumType.GetTypeInfo().IsEnum)
19-
#else
20-
if (!enumType.IsEnum)
21-
#endif
17+
if (!IsEnumType(enumType))
2218
throw new ArgumentException("Not an enumeration type", "enumType");
2319

2420
// We only want to parse single named constants
@@ -43,11 +39,7 @@ internal static Enum GetEnumValue(System.Type enumType, string s)
4339

4440
internal static Array GetEnumValues(System.Type enumType)
4541
{
46-
#if NEW_REFLECTION
47-
if (!enumType.GetTypeInfo().IsEnum)
48-
#else
49-
if (!enumType.IsEnum)
50-
#endif
42+
if (!IsEnumType(enumType))
5143
throw new ArgumentException("Not an enumeration type", "enumType");
5244

5345
#if NETCF_1_0 || NETCF_2_0 || SILVERLIGHT
@@ -73,5 +65,14 @@ internal static Enum GetArbitraryValue(System.Type enumType)
7365
int pos = (int)(DateTimeUtilities.CurrentUnixMs() & int.MaxValue) % values.Length;
7466
return (Enum)values.GetValue(pos);
7567
}
68+
69+
internal static bool IsEnumType(System.Type t)
70+
{
71+
#if NEW_REFLECTION
72+
return t.GetTypeInfo().IsEnum;
73+
#else
74+
return t.IsEnum;
75+
#endif
76+
}
7677
}
7778
}

0 commit comments

Comments
 (0)