Example #1
0
        private void UpdateNativeRegistrar()
        {
            if (registerNativeDelegate != null)
            {
                return;
            }

            BindingFlags bindingFlags = BindingFlags.Static | BindingFlags.Public;

            FieldInfo[] fields = typeof(TRegisterNativeDelegate).DeclaringType.GetFields(bindingFlags);
            foreach (FieldInfo field in fields)
            {
                if (field.IsStatic && field.FieldType == typeof(TRegisterNativeDelegate))
                {
                    registerNativeDelegate = field.GetValue(null) as TRegisterNativeDelegate;
                    if (registerNativeDelegate != null)
                    {
                        Delegate del = registerNativeDelegate as Delegate;

                        // Mono / .NET Framework have slightly different requirements for what we are doing with CreateDelegate
                        // - Mono requires firstArg to be null to create a valid delegate
                        // - NET Framework requires the del as context otherwise when the delegate is called an exception is thrown
                        object firstArg = null;
                        if (!AssemblyContext.IsMono)
                        {
                            firstArg = del;
                        }

                        if (IsMulticast)
                        {
                            registerNativeMulticastDelegateWrapper = (RegisterNativeMulticastDelegateWrapper)
                                                                     Delegate.CreateDelegate(typeof(RegisterNativeMulticastDelegateWrapper),
                                                                                             firstArg, del.Method);
                        }
                        else
                        {
                            registerNativeDelegateWrapper = (RegisterNativeDelegateWrapper)
                                                            Delegate.CreateDelegate(typeof(RegisterNativeDelegateWrapper),
                                                                                    firstArg, del.Method);
                        }
                    }
                    else
                    {
                        FMessage.Log(ELogVerbosity.Error, "Failed to find native delegate '" +
                                     typeof(TRegisterNativeDelegate).FullName + "'. Did you call REGISTER_FUNC()?");
                    }
                    break;
                }
            }
        }
Example #2
0
        private void UpdateNativeRegistrar()
        {
            if (registerNativeDelegate != null)
            {
                return;
            }

            BindingFlags bindingFlags = BindingFlags.Static | BindingFlags.Public;

            FieldInfo[] fields = typeof(TRegisterNativeDelegate).DeclaringType.GetFields(bindingFlags);
            foreach (FieldInfo field in fields)
            {
                if (field.IsStatic && field.FieldType == typeof(TRegisterNativeDelegate))
                {
                    registerNativeDelegate = field.GetValue(null) as TRegisterNativeDelegate;
                    if (registerNativeDelegate != null)
                    {
                        Delegate del = registerNativeDelegate as Delegate;
                        if (IsMulticast)
                        {
                            registerNativeMulticastDelegateWrapper = (RegisterNativeMulticastDelegateWrapper)
                                                                     Delegate.CreateDelegate(typeof(RegisterNativeMulticastDelegateWrapper),
                                                                                             del, del.Method);
                        }
                        else
                        {
                            registerNativeDelegateWrapper = (RegisterNativeDelegateWrapper)
                                                            Delegate.CreateDelegate(typeof(RegisterNativeDelegateWrapper),
                                                                                    del, del.Method);
                        }
                    }
                    else
                    {
                        FMessage.Log(ELogVerbosity.Error, "Failed to find native delegate '" +
                                     typeof(TRegisterNativeDelegate).FullName + "'. Did you call REGISTER_FUNC()?");
                    }
                    break;
                }
            }
        }