From da81fe89f8179dfbf7ae17753877c8ea1b179a8b Mon Sep 17 00:00:00 2001 From: Peter Dettman Date: Fri, 24 Jun 2022 11:51:46 +0700 Subject: NEW_REFLECTION cleanup --- crypto/src/util/Enums.cs | 28 +++++++--------------------- crypto/src/util/TypeExtensions.cs | 17 ----------------- 2 files changed, 7 insertions(+), 38 deletions(-) delete mode 100644 crypto/src/util/TypeExtensions.cs (limited to 'crypto/src/util') 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 -- cgit 1.4.1