Skip to content

Commit d92d46e

Browse files
committed
Adds a .NET 3.5 build option
1 parent 3e94a17 commit d92d46e

File tree

5 files changed

+55
-1
lines changed

5 files changed

+55
-1
lines changed

src/NativeLibraryUtilities/NativeDelegateInitializer.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,11 @@ public static Delegate SetupNativeDelegate(ILibraryInformation library, string n
4343
/// <param name="library">The object containing the native library to load from</param>
4444
public static void SetupNativeDelegates<T>(ILibraryInformation library)
4545
{
46+
#if NET35
47+
var info = typeof(T);
48+
#else
4649
TypeInfo info = typeof(T).GetTypeInfo();
50+
#endif
4751
#if NETSTANDARD
4852
MethodInfo getDelegateForFunctionPointer =
4953
typeof(Marshal).GetTypeInfo().GetMethods(BindingFlags.Static | BindingFlags.Public)
@@ -73,7 +77,11 @@ public static void SetupNativeDelegates<T>(ILibraryInformation library)
7377
public static List<string> GetNativeDelegateList<T>()
7478
{
7579
List<string> nativeList = new List<string>();
80+
#if NET35
81+
var info = typeof(T);
82+
#else
7683
TypeInfo info = typeof(T).GetTypeInfo();
84+
#endif
7785
foreach (FieldInfo field in info.GetFields(BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic))
7886
{
7987
var attribute = (NativeDelegateAttribute)field.GetCustomAttribute(typeof(NativeDelegateAttribute));
@@ -92,7 +100,11 @@ public static List<string> GetNativeDelegateList<T>()
92100
public static List<string> GetNativeDelegateList(Type type)
93101
{
94102
List<string> nativeList = new List<string>();
103+
#if NET35
104+
var info = type;
105+
#else
95106
TypeInfo info = type.GetTypeInfo();
107+
#endif
96108
foreach (FieldInfo field in info.GetFields(BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic))
97109
{
98110
var attribute = (NativeDelegateAttribute)field.GetCustomAttribute(typeof(NativeDelegateAttribute));

src/NativeLibraryUtilities/NativeLibraryLoader.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public void LoadNativeLibrary<T>(ILibraryLoader loader, string location, bool di
5858
throw new ArgumentNullException(nameof(location), "Library location cannot be null");
5959

6060
// Set to use temp file if extractLocation is null
61-
if (string.IsNullOrWhiteSpace(extractLocation) && !directLoad)
61+
if (StringUtil.IsNullOrWhiteSpace(extractLocation) && !directLoad)
6262
{
6363
extractLocation = Path.GetTempFileName();
6464
UsingTempFile = true;
@@ -251,7 +251,11 @@ private void ExtractNativeLibrary(string resourceLocation, string extractLocatio
251251

252252
private void ExtractNativeLibrary(string resourceLocation, string extractLocation, Type type)
253253
{
254+
#if NET35
255+
ExtractNativeLibrary(resourceLocation, extractLocation, type.Assembly);
256+
#else
254257
ExtractNativeLibrary(resourceLocation, extractLocation, type.GetTypeInfo().Assembly);
258+
#endif
255259
}
256260

257261
private static bool Is64BitOs()
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
using System;
2+
using System.Reflection;
3+
using System.Runtime.InteropServices;
4+
5+
namespace NativeLibraryUtilities
6+
{
7+
#if NET35
8+
internal static class Net35Extensions
9+
{
10+
11+
public static object GetCustomAttribute(this FieldInfo info, Type t)
12+
{
13+
return Attribute.GetCustomAttribute(info, t);
14+
}
15+
}
16+
#endif
17+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
namespace NativeLibraryUtilities
2+
{
3+
internal static class StringUtil
4+
{
5+
public static bool IsNullOrWhiteSpace(string value)
6+
{
7+
if (value == null) return true;
8+
9+
for(int i = 0; i < value.Length; i++) {
10+
if(!char.IsWhiteSpace(value[i])) return false;
11+
}
12+
13+
return true;
14+
}
15+
}
16+
}

src/NativeLibraryUtilities/project.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,11 @@
3131
},
3232
"frameworks": {
3333
"net45": {},
34+
"net35": {
35+
"buildOptions": {
36+
"define": [ "NET35" ]
37+
}
38+
},
3439
"netstandard1.5": {
3540
"buildOptions": {
3641
"define": [ "NETSTANDARD" ]

0 commit comments

Comments
 (0)