コード例 #1
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);
        }
コード例 #2
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);
        }
コード例 #3
0
        internal IDelegateAdapter FindDelegateAdapter(ILTypeInstance instance, ILMethod method)
        {
            IDelegateAdapter res;

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

                    return(res);
                }
                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)
                            {
                                //UnityEngine.Debug.Log(i.ParameterTypes[j].Name + "=====" + method.Parameters[j].TypeForCLR.Name);
                                if (mGernericsMapper.ContainsKey(i.ParameterTypes[j].Name))
                                {
                                    mClsNameTemp = mGernericsMapper[i.ParameterTypes[j].Name];
                                    if (mClsNameTemp == method.Parameters[j].TypeForCLR.Name)
                                    {
                                        //UnityEngine.Debug.Log("Match by another way!!!");
                                        match = true;
                                        break;
                                    }
                                    else
                                    {
                                        //UnityEngine.Debug.Log(mClsNameTemp + " == " + method.Parameters[j].TypeForCLR.Name);
                                    }
                                    //UnityEngine.Debug.Log(mClsNameTemp + "=====" + method.Parameters[j].TypeForCLR.Name);
                                }
                                match = false;
                                break;
                            }
                        }
                        if (match)
                        {
                            res = i.Adapter.Instantiate(appdomain, instance, method);
                            if (instance != null)
                            {
                                instance.SetDelegateAdapter(method, res);
                            }

                            return(res);
                        }
                    }
                }
            }
            else
            {
                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])
                            {
                                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);
        }
コード例 #4
0
        internal IDelegateAdapter FindDelegateAdapter(ILTypeInstance instance, ILMethod method)
        {
            if (method.ReturnType == appdomain.VoidType)
            {
                if (method.ParameterCount == 0)
                {
                    var res = zeroParamMethodAdapter.Instantiate(appdomain, instance, method);
                    if (instance != null)
                    {
                        instance.SetDelegateAdapter(method, res);
                    }
                    return(res);
                }
                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)
                        {
                            var res = i.Adapter.Instantiate(appdomain, instance, method);
                            if (instance != null)
                            {
                                instance.SetDelegateAdapter(method, res);
                            }
                            return(res);
                        }
                    }
                }
            }
            else
            {
                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])
                            {
                                var res = i.Adapter.Instantiate(appdomain, instance, method);
                                if (instance != null)
                                {
                                    instance.SetDelegateAdapter(method, res);
                                }
                                return(res);
                            }
                        }
                    }
                }
            }

            throw new KeyNotFoundException("Cannot find Delegate Adapter for:" + method);
        }
コード例 #5
0
ファイル: DelegateManager.cs プロジェクト: ErQing/XIL
        /// <summary>
        /// ilMethod代表的delegate会赋值给method对应的delegate,一般两者参数类型都一致,
        /// 但新版本的支持泛型协变之后,有些时候会不一致,所以此处判断是用method判断,而不是用ilMethod判断
        /// </summary>
        /// <param name="instance"></param>
        /// <param name="ilMethod"></param>
        /// <param name="method"></param>
        /// <returns></returns>
        internal IDelegateAdapter FindDelegateAdapter(ILTypeInstance instance, ILMethod ilMethod, IMethod method)
        {
            IDelegateAdapter res;
            var parameterCount   = method.ParameterCount;
            var returnTypeForCLR = method.ReturnType.TypeForCLR;

            if (method.ReturnType == appdomain.VoidType)
            {
                if (parameterCount == 0)
                {
                    res = zeroParamMethodAdapter.Instantiate(appdomain, instance, ilMethod);
                    if (instance != null)
                    {
                        instance.SetDelegateAdapter(ilMethod, res);
                    }
                    return(res);
                }
                foreach (var i in methods)
                {
                    var parameterTypes = i.ParameterTypes;
                    if (parameterTypes.Length == parameterCount)
                    {
                        bool match = true;
                        for (int j = 0; j < parameterCount; j++)
                        {
                            if (parameterTypes[j] != method.Parameters[j].TypeForCLR)
                            {
                                match = false;
                                break;
                            }
                        }
                        if (match)
                        {
                            res = i.Adapter.Instantiate(appdomain, instance, ilMethod);
                            if (instance != null)
                            {
                                instance.SetDelegateAdapter(ilMethod, res);
                            }
                            return(res);
                        }
                    }
                }
            }
            else
            {
                foreach (var i in functions)
                {
                    var parameterTypes = i.ParameterTypes;
                    if (parameterTypes.Length == parameterCount + 1)
                    {
                        bool match = true;
                        for (int j = 0; j < parameterCount; j++)
                        {
                            if (parameterTypes[j] != method.Parameters[j].TypeForCLR)
                            {
                                match = false;
                                break;
                            }
                        }
                        if (match)
                        {
                            if (returnTypeForCLR == parameterTypes[parameterCount])
                            {
                                res = i.Adapter.Instantiate(appdomain, instance, ilMethod);
                                if (instance != null)
                                {
                                    instance.SetDelegateAdapter(ilMethod, res);
                                }
                                return(res);
                            }
                        }
                    }
                }
            }

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