예제 #1
0
        public static void MapLibraryToType <TType>(IDynamicLibrary DynamicLibrary)
        {
            var Type = typeof(TType);

            foreach (var Field in Type.GetFields(BindingFlags.Public | BindingFlags.Static))
            {
                if (Field.FieldType.IsSubclassOf(typeof(Delegate)))
                {
                    if (Field.GetValue(null) == null)
                    {
                        var Method = DynamicLibrary.GetMethod(Field.Name);
                        if (Method != IntPtr.Zero)
                        {
                            Field.SetValue(
                                null,
                                Marshal.GetDelegateForFunctionPointer(
                                    Method,
                                    Field.FieldType
                                    )
                                );
                        }
                        else
                        {
                            //Console.WriteLine(Field.Name);
                        }
                    }
                }
            }
        }
예제 #2
0
        public static void MapLibraryToType <TType>(IDynamicLibrary dynamicLibrary)
        {
            var type = typeof(TType);

            foreach (var field in type.GetFields(BindingFlags.Public | BindingFlags.Static))
            {
                if (!field.FieldType.IsSubclassOf(typeof(Delegate)))
                {
                    continue;
                }
                if (field.GetValue(null) != null)
                {
                    continue;
                }
                var method = dynamicLibrary.GetMethod(field.Name);
                Console.WriteLine($"{field.Name} : {method}");
                if (method != IntPtr.Zero)
                {
                    field.SetValue(
                        null,
                        Marshal.GetDelegateForFunctionPointer(method, field.FieldType)
                        );
                }
                else
                {
                    //Console.WriteLine(Field.Name);
                }
            }
        }