diff options
author | Peter Dettman <peter.dettman@bouncycastle.org> | 2015-11-21 23:39:33 +0700 |
---|---|---|
committer | Peter Dettman <peter.dettman@bouncycastle.org> | 2015-11-21 23:39:33 +0700 |
commit | cead3acdc4320de1a8d5ff810f3fe4a87c3e4f61 (patch) | |
tree | c7a5795f5152d4e36d60f8d4c7ac518a203976f8 /crypto | |
parent | Update .gitignore (diff) | |
download | BouncyCastle.NET-ed25519-cead3acdc4320de1a8d5ff810f3fe4a87c3e4f61.tar.xz |
Factor out IsEnumType method
Diffstat (limited to 'crypto')
-rw-r--r-- | crypto/src/util/Enums.cs | 21 |
1 files changed, 11 insertions, 10 deletions
diff --git a/crypto/src/util/Enums.cs b/crypto/src/util/Enums.cs index 660bbe73f..9e908c4c0 100644 --- a/crypto/src/util/Enums.cs +++ b/crypto/src/util/Enums.cs @@ -14,11 +14,7 @@ namespace Org.BouncyCastle.Utilities { internal static Enum GetEnumValue(System.Type enumType, string s) { -#if NEW_REFLECTION - if (!enumType.GetTypeInfo().IsEnum) -#else - if (!enumType.IsEnum) -#endif + if (!IsEnumType(enumType)) throw new ArgumentException("Not an enumeration type", "enumType"); // We only want to parse single named constants @@ -43,11 +39,7 @@ namespace Org.BouncyCastle.Utilities internal static Array GetEnumValues(System.Type enumType) { -#if NEW_REFLECTION - if (!enumType.GetTypeInfo().IsEnum) -#else - if (!enumType.IsEnum) -#endif + if (!IsEnumType(enumType)) throw new ArgumentException("Not an enumeration type", "enumType"); #if NETCF_1_0 || NETCF_2_0 || SILVERLIGHT @@ -73,5 +65,14 @@ namespace Org.BouncyCastle.Utilities int pos = (int)(DateTimeUtilities.CurrentUnixMs() & int.MaxValue) % values.Length; return (Enum)values.GetValue(pos); } + + internal static bool IsEnumType(System.Type t) + { +#if NEW_REFLECTION + return t.GetTypeInfo().IsEnum; +#else + return t.IsEnum; +#endif + } } } |