File tree 1 file changed +27
-1
lines changed
src/NativeLibraryUtilities
1 file changed +27
-1
lines changed Original file line number Diff line number Diff line change 1
- using System . Reflection ;
1
+ using System ;
2
+ using System . Reflection ;
2
3
using System . Runtime . InteropServices ;
3
4
using System . Linq ;
4
5
@@ -9,6 +10,31 @@ namespace NativeLibraryUtilities
9
10
/// </summary>
10
11
public static class NativeDelegateInitializer
11
12
{
13
+ #if NETSTANDARD
14
+ /// <summary>
15
+ /// Loads and setups a native delegate.
16
+ /// </summary>
17
+ /// <param name="library">The library to load from</param>
18
+ /// <param name="nativeName">The native function name to load</param>
19
+ /// <returns>A delegate that will call the native function</returns>
20
+ public static T SetupNativeDelegate < T > ( ILibraryInformation library , string nativeName )
21
+ {
22
+ return Marshal . GetDelegateForFunctionPointer < T > ( library . LibraryLoader . GetProcAddress ( nativeName ) ) ;
23
+ }
24
+ #else
25
+ /// <summary>
26
+ /// Loads and setups a native delegate.
27
+ /// </summary>
28
+ /// <param name="library">The library to load from</param>
29
+ /// <param name="nativeName">The native function name to load</param>
30
+ /// <param name="delegateType">The type of delegate to create</param>
31
+ /// <returns>A delegate that will call the native function</returns>
32
+ public static Delegate SetupNativeDelegate ( ILibraryInformation library , string nativeName , Type delegateType )
33
+ {
34
+ return Marshal . GetDelegateForFunctionPointer ( library . LibraryLoader . GetProcAddress ( nativeName ) , delegateType ) ;
35
+ }
36
+ #endif
37
+
12
38
/// <summary>
13
39
/// Sets up all native delegate in the type passed as the generic parameter
14
40
/// </summary>
You can’t perform that action at this time.
0 commit comments