Skip to content

Commit 211a94c

Browse files
committed
Moved all the code into the Libraries.Net47.cs and split with preprocessor directive check
1 parent d6f2685 commit 211a94c

File tree

2 files changed

+33
-31
lines changed

2 files changed

+33
-31
lines changed

Yubico.Core/src/Yubico/PlatformInterop/Libraries.Net47.cs

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
// limitations under the License.
1414

1515
#if NET47
16+
1617
using System;
1718
using System.IO;
1819

@@ -23,6 +24,33 @@ namespace Yubico.PlatformInterop
2324
/// </summary>
2425
internal static partial class Libraries
2526
{
27+
/// <summary>
28+
/// The filename of the native shims library for .NET Framework 4.7.
29+
/// </summary>
30+
/// <remarks>
31+
/// For .NET Framework 4.7, the DLL must be placed in an architecture-specific subdirectory:
32+
/// - x86/Yubico.NativeShims.dll for 32-bit processes
33+
/// - x64/Yubico.NativeShims.dll for 64-bit processes
34+
/// The correct version is loaded at runtime based on the process architecture.
35+
/// </remarks>
36+
internal const string NativeShims = "Yubico.NativeShims.dll";
37+
38+
/// <summary>
39+
/// Ensures the native library is properly loaded for .NET Framework 4.7.
40+
/// </summary>
41+
/// <exception cref="DllNotFoundException">
42+
/// Thrown when the native library cannot be loaded. This could be due to:
43+
/// - Missing DLL file in the architecture-specific directory (x86/x64)
44+
/// - Incorrect architecture (x86/x64 mismatch)
45+
/// - Missing dependencies
46+
/// - Insufficient permissions
47+
/// </exception>
48+
/// <remarks>
49+
/// This method must be called before any P/Invoke calls are made.
50+
/// The implementation details are handled in Libraries.Net47.cs.
51+
/// </remarks>
52+
public static void EnsureInitialized() => Net47Implementation.Initialize();
53+
2654
/// <summary>
2755
/// Encapsulates the .NET Framework 4.7 specific implementation details for native library management.
2856
/// This nested class handles the dynamic loading of architecture-specific (x86/x64) native libraries.
@@ -48,7 +76,7 @@ private static class Net47Implementation
4876
? "x64"
4977
: "x86",
5078
NativeShims);
51-
79+
5280
/// <summary>
5381
/// Initializes the native library for the current architecture.
5482
/// </summary>

Yubico.Core/src/Yubico/PlatformInterop/Libraries.cs

Lines changed: 4 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
using System;
15+
// As long as we have the Libraries.Net47.cs class which holds the opposite preprocessor directive check,
16+
// this check is required - as having both at the same time is not possible.
17+
#if !NET47
1618

1719
namespace Yubico.PlatformInterop
1820
{
@@ -35,34 +37,6 @@ namespace Yubico.PlatformInterop
3537
/// </remarks>
3638
internal static partial class Libraries
3739
{
38-
#if NET47
39-
/// <summary>
40-
/// The filename of the native shims library for .NET Framework 4.7.
41-
/// </summary>
42-
/// <remarks>
43-
/// For .NET Framework 4.7, the DLL must be placed in an architecture-specific subdirectory:
44-
/// - x86/Yubico.NativeShims.dll for 32-bit processes
45-
/// - x64/Yubico.NativeShims.dll for 64-bit processes
46-
/// The correct version is loaded at runtime based on the process architecture.
47-
/// </remarks>
48-
internal const string NativeShims = "Yubico.NativeShims.dll";
49-
50-
/// <summary>
51-
/// Ensures the native library is properly loaded for .NET Framework 4.7.
52-
/// </summary>
53-
/// <exception cref="DllNotFoundException">
54-
/// Thrown when the native library cannot be loaded. This could be due to:
55-
/// - Missing DLL file in the architecture-specific directory (x86/x64)
56-
/// - Incorrect architecture (x86/x64 mismatch)
57-
/// - Missing dependencies
58-
/// - Insufficient permissions
59-
/// </exception>
60-
/// <remarks>
61-
/// This method must be called before any P/Invoke calls are made.
62-
/// The implementation details are handled in Libraries.Net47.cs.
63-
/// </remarks>
64-
public static void EnsureInitialized() => Net47Implementation.Initialize();
65-
#else
6640
/// <summary>
6741
/// The filename of the native shims library for modern .NET versions.
6842
/// </summary>
@@ -81,6 +55,6 @@ internal static partial class Libraries
8155
/// This method exists only for API compatibility with .NET Framework 4.7 code.
8256
/// </remarks>
8357
public static void EnsureInitialized() { }
84-
#endif
8558
}
8659
}
60+
#endif

0 commit comments

Comments
 (0)