Пример #1
0
        public override Delegate CreateDelegate(Type delegateType, object target)
        {
            ILTypeInstance ilTypeInstance;

            if (target is ILTypeInstance)
            {
                ilTypeInstance = target as ILTypeInstance;
            }
            else if (target is CrossBindingAdaptorType adaptor)
            {
                ilTypeInstance = adaptor.ILInstance;
            }
            else
            {
                return(CreateDelegate(delegateType));
            }

            IDelegateAdapter del;

            if (iDelegate == null)
            {
                iDelegate = appdomain.DelegateManager.FindDelegateAdapter(ilTypeInstance, method, method);
                del       = iDelegate;
            }
            else
            {
                del = iDelegate.Instantiate(appdomain, ilTypeInstance, iDelegate.Method);
            }
            return(del.Delegate);
        }
Пример #2
0
        private IDelegateAdapter GetFunctionAdapter(ILTypeInstance instance, ILMethod method)
        {
            IDelegateAdapter adapter = null;
            int paramCount           = method.ParameterCount;

            switch (paramCount)
            {
            case 0:
            {
                if (m_functions_1.ContainsKey(method.ReturnType.TypeForCLR))
                {
                    adapter = m_functions_1[method.ReturnType.TypeForCLR];
                }
                break;
            }

            case 1:
            {
                if (m_functions_2.ContainsKey(method.Parameters[0].TypeForCLR))
                {
                    var dic = m_functions_2[method.Parameters[0].TypeForCLR];
                    adapter = GetFunctionAdapter(instance, method, 0, dic);
                }
                break;
            }

            case 2:
            {
                if (m_functions_3.ContainsKey(method.Parameters[0].TypeForCLR))
                {
                    var dic = m_functions_3[method.Parameters[0].TypeForCLR];
                    adapter = GetFunctionAdapter(instance, method, 0, dic);
                }
                break;
            }

            case 3:
            {
                if (m_functions_4.ContainsKey(method.Parameters[0].TypeForCLR))
                {
                    var dic = m_functions_4[method.Parameters[0].TypeForCLR];
                    adapter = GetFunctionAdapter(instance, method, 0, dic);
                }
                break;
            }

            case 4:
            {
                if (m_functions_5.ContainsKey(method.Parameters[0].TypeForCLR))
                {
                    var dic = m_functions_5[method.Parameters[0].TypeForCLR];
                    adapter = GetFunctionAdapter(instance, method, 0, dic);
                }
                break;
            }

            case 5:
            {
                if (m_functions_6.ContainsKey(method.Parameters[0].TypeForCLR))
                {
                    var dic = m_functions_6[method.Parameters[0].TypeForCLR];
                    adapter = GetFunctionAdapter(instance, method, 0, dic);
                }
                break;
            }
            }
            if (adapter == null)
            {
                return(null);
            }
            var res = adapter.Instantiate(appdomain, instance, method);

            if (instance != null)
            {
                instance.SetDelegateAdapter(method, res);
            }
            return(res);
        }
Пример #3
0
        internal IDelegateAdapter FindDelegateAdapter(ILTypeInstance instance, ILMethod method)
        {
            IDelegateAdapter res = null;

            if (method.ReturnType == appdomain.VoidType)
            {
                if (method.ParameterCount == 0)
                {
                    res = zeroParamMethodAdapter.Instantiate(appdomain, instance, method);
                    if (instance != null)
                    {
                        instance.SetDelegateAdapter(method, res);
                    }
                    return(res);
                }

                res = GetMethodAdapter(instance, method);
                if (res != null)
                {
                    return(res);
                }
                else if (false)
                {
                    foreach (var i in methods)
                    {
                        if (i.ParameterTypes.Length == method.ParameterCount)
                        {
                            bool match = true;
                            for (int j = 0; j < method.ParameterCount; j++)
                            {
                                if (i.ParameterTypes[j] != method.Parameters[j].TypeForCLR)
                                {
                                    match = false;
                                    break;
                                }
                            }
                            if (match)
                            {
                                UnityEngine.Debug.Log("快速查找没有找到,但是老的查找却找到了的!");
                                res = i.Adapter.Instantiate(appdomain, instance, method);
                                if (instance != null)
                                {
                                    instance.SetDelegateAdapter(method, res);
                                }
                                return(res);
                            }
                        }
                    }
                }
            }
            else
            {
                res = GetFunctionAdapter(instance, method);
                if (res != null)
                {
                    return(res);
                }
                else if (false)
                {
                    foreach (var i in functions)
                    {
                        if (i.ParameterTypes.Length == method.ParameterCount + 1)
                        {
                            bool match = true;
                            for (int j = 0; j < method.ParameterCount; j++)
                            {
                                if (i.ParameterTypes[j] != method.Parameters[j].TypeForCLR)
                                {
                                    match = false;
                                    break;
                                }
                            }
                            if (match)
                            {
                                if (method.ReturnType.TypeForCLR == i.ParameterTypes[method.ParameterCount])
                                {
                                    UnityEngine.Debug.Log("快速查找没有找到,但是老的查找却找到了的!");
                                    res = i.Adapter.Instantiate(appdomain, instance, method);
                                    if (instance != null)
                                    {
                                        instance.SetDelegateAdapter(method, res);
                                    }
                                    return(res);
                                }
                            }
                        }
                    }
                }
            }

            res = dummyAdapter.Instantiate(appdomain, instance, method);
            if (instance != null)
            {
                instance.SetDelegateAdapter(method, res);
            }
            return(res);
        }