Skip to content

Commit 3e94a17

Browse files
committed
Adds way to get list of native symbols for testing purposes
1 parent 3dbfd36 commit 3e94a17

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

src/NativeLibraryUtilities/NativeDelegateInitializer.cs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System;
2+
using System.Collections.Generic;
23
using System.Reflection;
34
using System.Runtime.InteropServices;
45
using System.Linq;
@@ -63,5 +64,43 @@ public static void SetupNativeDelegates<T>(ILibraryInformation library)
6364
field.SetValue(null, setVal);
6465
}
6566
}
67+
68+
/// <summary>
69+
/// Gets a list of all all native delegates in the type passed as the generic parameter
70+
/// </summary>
71+
/// <typeparam name="T">The type to setup the native delegates in</typeparam>
72+
/// <returns>A list of all native delegates that are being requested</returns>
73+
public static List<string> GetNativeDelegateList<T>()
74+
{
75+
List<string> nativeList = new List<string>();
76+
TypeInfo info = typeof(T).GetTypeInfo();
77+
foreach (FieldInfo field in info.GetFields(BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic))
78+
{
79+
var attribute = (NativeDelegateAttribute)field.GetCustomAttribute(typeof(NativeDelegateAttribute));
80+
if (attribute == null) continue;
81+
string nativeName = attribute.NativeName ?? field.Name;
82+
nativeList.Add(nativeName);
83+
}
84+
return nativeList;
85+
}
86+
87+
/// <summary>
88+
/// Gets a list of all all native delegates in the type passed as the generic parameter
89+
/// </summary>
90+
/// <param name="type">The type to setup the native delegates in</param>
91+
/// <returns>A list of all native delegates that are being requested</returns>
92+
public static List<string> GetNativeDelegateList(Type type)
93+
{
94+
List<string> nativeList = new List<string>();
95+
TypeInfo info = type.GetTypeInfo();
96+
foreach (FieldInfo field in info.GetFields(BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic))
97+
{
98+
var attribute = (NativeDelegateAttribute)field.GetCustomAttribute(typeof(NativeDelegateAttribute));
99+
if (attribute == null) continue;
100+
string nativeName = attribute.NativeName ?? field.Name;
101+
nativeList.Add(nativeName);
102+
}
103+
return nativeList;
104+
}
66105
}
67106
}

0 commit comments

Comments
 (0)