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 | |
parent | Some modern syntax updates (diff) | |
download | BouncyCastle.NET-ed25519-da81fe89f8179dfbf7ae17753877c8ea1b179a8b.tar.xz |
NEW_REFLECTION cleanup
-rw-r--r-- | crypto/src/AssemblyInfo.cs | 51 | ||||
-rw-r--r-- | crypto/src/bcpg/ArmoredOutputStream.cs | 2 | ||||
-rw-r--r-- | crypto/src/util/Enums.cs | 28 | ||||
-rw-r--r-- | crypto/src/util/TypeExtensions.cs | 17 |
4 files changed, 9 insertions, 89 deletions
diff --git a/crypto/src/AssemblyInfo.cs b/crypto/src/AssemblyInfo.cs index 568ecf594..f89d58fbd 100644 --- a/crypto/src/AssemblyInfo.cs +++ b/crypto/src/AssemblyInfo.cs @@ -1,17 +1,8 @@ using System; -using System.Reflection; -using System.Runtime.CompilerServices; - -#if PORTABLE -using System.Linq; -#else using System.Runtime.InteropServices; -#endif [assembly: CLSCompliant(true)] -#if !PORTABLE [assembly: ComVisible(false)] -#endif // Start with no permissions //[assembly: PermissionSet(SecurityAction.RequestOptional, Unrestricted=false)] @@ -20,46 +11,7 @@ using System.Runtime.InteropServices; // see Org.BouncyCastle.Crypto.Encodings.Pkcs1Encoding.StrictLengthEnabledProperty //[assembly: EnvironmentPermission(SecurityAction.RequestOptional, Read="Org.BouncyCastle.Pkcs1.Strict")] -internal class AssemblyInfo -{ - private static string version = null; - - public static string Version - { - get - { - if (version == null) - { -#if PORTABLE -#if NEW_REFLECTION - var a = typeof(AssemblyInfo).GetTypeInfo().Assembly; - var c = a.GetCustomAttributes(typeof(AssemblyVersionAttribute)); -#else - var a = typeof(AssemblyInfo).Assembly; - var c = a.GetCustomAttributes(typeof(AssemblyVersionAttribute), false); -#endif - var v = (AssemblyVersionAttribute)c.FirstOrDefault(); - if (v != null) - { - version = v.Version; - } -#else - version = typeof(AssemblyInfo).Assembly.GetName().Version.ToString(); -#endif - - // if we're still here, then don't try again - if (version == null) - { - version = string.Empty; - } - } - - return version; - } - } -} - -#if NET40 +#if !(NET45_OR_GREATER || NETSTANDARD1_0_OR_GREATER) namespace System.Reflection { [AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true, Inherited = false)] @@ -76,5 +28,4 @@ namespace System.Reflection public string Value { get; } } } - #endif diff --git a/crypto/src/bcpg/ArmoredOutputStream.cs b/crypto/src/bcpg/ArmoredOutputStream.cs index 97bcbde51..919325a73 100644 --- a/crypto/src/bcpg/ArmoredOutputStream.cs +++ b/crypto/src/bcpg/ArmoredOutputStream.cs @@ -103,7 +103,7 @@ namespace Org.BouncyCastle.Bcpg private static readonly string footerStart = "-----END PGP "; private static readonly string footerTail = "-----"; - private static readonly string Version = "BCPG C# v" + AssemblyInfo.Version; + private static readonly string Version = "BCPG C# v" + typeof(ArmoredOutputStream).Assembly.GetName().Version; private readonly IDictionary headers; 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 |