|
1 | 1 | using System;
|
| 2 | +using System.Collections.Generic; |
2 | 3 | using System.Reflection;
|
3 | 4 | using System.Runtime.InteropServices;
|
4 | 5 | using System.Linq;
|
@@ -63,5 +64,43 @@ public static void SetupNativeDelegates<T>(ILibraryInformation library)
|
63 | 64 | field.SetValue(null, setVal);
|
64 | 65 | }
|
65 | 66 | }
|
| 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 | + } |
66 | 105 | }
|
67 | 106 | }
|
0 commit comments