From 995255e51334878901fca7bfd2069393abd32339 Mon Sep 17 00:00:00 2001 From: Peter Dettman Date: Thu, 16 Jun 2022 23:32:53 +0700 Subject: Alternative for GetExecutingAssembly --- crypto.tests.Net45/crypto.tests.Net45.csproj | 2 +- crypto/test/src/util/test/SimpleTest.cs | 22 +++++++++++++++------- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/crypto.tests.Net45/crypto.tests.Net45.csproj b/crypto.tests.Net45/crypto.tests.Net45.csproj index de668a83d..729043d39 100644 --- a/crypto.tests.Net45/crypto.tests.Net45.csproj +++ b/crypto.tests.Net45/crypto.tests.Net45.csproj @@ -17,7 +17,7 @@ full false bin\Debug\ - TRACE;DEBUG;LIB;PORTABLE + TRACE;DEBUG;LIB;PORTABLE;NEW_REFLECTION prompt 4 diff --git a/crypto/test/src/util/test/SimpleTest.cs b/crypto/test/src/util/test/SimpleTest.cs index a40ff2961..b2eb670ff 100644 --- a/crypto/test/src/util/test/SimpleTest.cs +++ b/crypto/test/src/util/test/SimpleTest.cs @@ -2,9 +2,6 @@ using System; using System.Collections; using System.IO; using System.Reflection; -using System.Text; - -using Org.BouncyCastle.Utilities; namespace Org.BouncyCastle.Utilities.Test { @@ -143,7 +140,7 @@ namespace Org.BouncyCastle.Utilities.Test { string fullName = GetFullName(name); - return Assembly.GetExecutingAssembly().GetManifestResourceStream(fullName); + return GetAssembly().GetManifestResourceStream(fullName); } internal static string[] GetTestDataEntries( @@ -152,7 +149,7 @@ namespace Org.BouncyCastle.Utilities.Test string fullPrefix = GetFullName(prefix); ArrayList result = new ArrayList(); - string[] fullNames = Assembly.GetExecutingAssembly().GetManifestResourceNames(); + string[] fullNames = GetAssembly().GetManifestResourceNames(); foreach (string fullName in fullNames) { if (fullName.StartsWith(fullPrefix)) @@ -161,10 +158,21 @@ namespace Org.BouncyCastle.Utilities.Test result.Add(name); } } - return (string[])result.ToArray(typeof(String)); + return (string[])result.ToArray(typeof(string)); } - private static string GetFullName( + private static Assembly GetAssembly() + { +#if !PORTABLE + return Assembly.GetExecutingAssembly(); +#elif NEW_REFLECTION + return typeof(SimpleTest).GetTypeInfo().Assembly; +#else + return typeof(SimpleTest).Assembly; +#endif + } + + private static string GetFullName( string name) { #if SEPARATE_UNIT_TESTS -- cgit 1.4.1