diff options
author | Peter Dettman <peter.dettman@bouncycastle.org> | 2022-06-24 11:51:46 +0700 |
---|---|---|
committer | Peter Dettman <peter.dettman@bouncycastle.org> | 2022-06-24 11:51:46 +0700 |
commit | da81fe89f8179dfbf7ae17753877c8ea1b179a8b (patch) | |
tree | 1575aeedd80dd1a47de8367ca90f601fd15d1f49 /crypto/src/util | |
parent | Some modern syntax updates (diff) | |
download | BouncyCastle.NET-ed25519-da81fe89f8179dfbf7ae17753877c8ea1b179a8b.tar.xz |
NEW_REFLECTION cleanup
Diffstat (limited to 'crypto/src/util')
-rw-r--r-- | crypto/src/util/Enums.cs | 28 | ||||
-rw-r--r-- | crypto/src/util/TypeExtensions.cs | 17 |
2 files changed, 7 insertions, 38 deletions
diff --git a/crypto/src/util/Enums.cs b/crypto/src/util/Enums.cs index c369511d4..fb685e2a7 100644 --- a/crypto/src/util/Enums.cs +++ b/crypto/src/util/Enums.cs @@ -1,20 +1,15 @@ using System; -#if PORTABLE -using System.Collections; -using System.Reflection; -#endif - using Org.BouncyCastle.Utilities.Date; namespace Org.BouncyCastle.Utilities { internal abstract class Enums { - internal static Enum GetEnumValue(System.Type enumType, string s) + internal static Enum GetEnumValue(Type enumType, string s) { - if (!IsEnumType(enumType)) - throw new ArgumentException("Not an enumeration type", "enumType"); + if (!enumType.IsEnum) + throw new ArgumentException("Not an enumeration type", nameof(enumType)); // We only want to parse single named constants if (s.Length > 0 && char.IsLetter(s[0]) && s.IndexOf(',') < 0) @@ -28,28 +23,19 @@ namespace Org.BouncyCastle.Utilities throw new ArgumentException(); } - internal static Array GetEnumValues(System.Type enumType) + internal static Array GetEnumValues(Type enumType) { - if (!IsEnumType(enumType)) - throw new ArgumentException("Not an enumeration type", "enumType"); + if (!enumType.IsEnum) + throw new ArgumentException("Not an enumeration type", nameof(enumType)); return Enum.GetValues(enumType); } - internal static Enum GetArbitraryValue(System.Type enumType) + internal static Enum GetArbitraryValue(Type enumType) { Array values = GetEnumValues(enumType); 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 - } } } diff --git a/crypto/src/util/TypeExtensions.cs b/crypto/src/util/TypeExtensions.cs deleted file mode 100644 index e2aeae4dc..000000000 --- a/crypto/src/util/TypeExtensions.cs +++ /dev/null @@ -1,17 +0,0 @@ -#if NEW_REFLECTION - -using System; -using System.Reflection; - -namespace Org.BouncyCastle -{ - internal static class TypeExtensions - { - public static bool IsInstanceOfType(this Type type, object instance) - { - return instance != null && type.GetTypeInfo().IsAssignableFrom(instance.GetType().GetTypeInfo()); - } - } -} - -#endif |