示例#1
0
 private bool IsEqualLMethodInfo(LMethodInfo info0, LMethodInfo info1)
 {
     if (info0.m_ReturnString != info1.m_ReturnString)
     {
         return(false);
     }
     if (info0.m_Params.Count != info1.m_Params.Count)
     {
         return(false);
     }
     for (int i = 0; i < info0.m_Params.Count; ++i)
     {
         var paramData0 = info0.m_Params[i];
         var paramData1 = info1.m_Params[i];
         if (paramData0.m_ParamString != paramData1.m_ParamString)
         {
             return(false);
         }
         if (paramData0.m_RefOut != paramData1.m_RefOut)
         {
             return(false);
         }
     }
     return(true);
 }
示例#2
0
        private string WriteRegisterDelegateConvertor(string method_delegate, LMethodInfo info)
        {
            bool   isAction         = info.m_ReturnString.ToLower().Contains("void");
            string paramstrings     = "";
            string paramTypestrings = "";
            int    index            = 0;

            foreach (var p in info.m_Params)
            {
                paramTypestrings += p.m_ParamString;
                paramstrings     += "arg" + index;
                if (index < info.m_Params.Count - 1)
                {
                    paramTypestrings += ",";
                    paramstrings     += ",";
                }

                index++;
            }
            if (!isAction)
            {
                if (info.m_Params.Count == 0)
                {
                    paramTypestrings = info.m_ReturnString;
                }
                else
                {
                    paramTypestrings += "," + info.m_ReturnString;
                }
            }

            paramTypestrings = (string.IsNullOrEmpty(paramTypestrings) ? "" : ("<" + paramTypestrings + ">"));
            string regDelegate = "appDomain.DelegateManager.Register" + (isAction ? "Method" : "Function") + "Delegate" + paramTypestrings + "();\r\n";

            if (string.IsNullOrEmpty(paramTypestrings))
            {
                regDelegate = "";
            }
            string convertor =
                "   appDomain.DelegateManager.RegisterDelegateConvertor<LCLFunctionDelegate." + method_delegate + ">((act) =>\r\n" +
                "   {\r\n" +
                "       return new LCLFunctionDelegate." + method_delegate + "((" + paramstrings + ") =>\r\n" +
                "       {\r\n" +
                "       " + (isAction?"":"return ") + "((" + (isAction ? "Action" : "Func") + paramTypestrings + ")act)(" + paramstrings + ");\r\n" +
                "       });\r\n" +
                "   });\r\n";

            return(regDelegate + convertor);
        }
示例#3
0
        private List <LMethodInfo> LoadAssembly(string assemblyName)
        {
            List <LMethodInfo> funcLines = new List <LMethodInfo>();

            m_Assembly = Assembly.LoadFile(assemblyName);
            var types = m_Assembly.GetTypes();

            Filter.NeedInjects.Clear();
            //从所有类和参数中寻找需要处理的方法
            List <MethodInfoSource> methodList = new List <MethodInfoSource>();

            ParseTypes(types, methodList);
            List <MethodInfoSource> dealmethod = new List <MethodInfoSource>();

            foreach (var methodinfoSource in methodList)
            {
                var methodinfo = methodinfoSource.mothodInfo;
                if (!FilterMethod(methodinfoSource, dealmethod))
                {
                    //添加委托信息
                    LMethodInfo info           = new LMethodInfo();
                    var         returnparamter = methodinfo.ReturnParameter;
                    info.m_ReturnString = GetTypeName(returnparamter.ParameterType);
                    if (info.m_ReturnString.Contains("Void"))
                    {
                        info.m_ReturnString = "void";
                    }

                    var paramters = methodinfo.GetParameters();
                    if (paramters != null)
                    {
                        //为每一个普通的方法添加this的object,这个方法一般是需要注入的方法
                        if (methodinfoSource.source == MethodInfoSourceEnum.InjectMethod)
                        {
                            info.m_Params.Add(new ParamData()
                            {
                                m_ParamString = "System.Object", m_RefOut = RefOutArrayEnum.None
                            });
                        }
                        foreach (var pi in paramters)
                        {
                            ParamData paramdata = new ParamData();
                            if (pi.ParameterType.IsArray)
                            {
                                paramdata.m_RefOut = RefOutArrayEnum.Array;
                            }

                            paramdata.m_ParamString = GetTypeName(pi.ParameterType);
                            info.m_Params.Add(paramdata);
                        }
                    }
                    funcLines.Add(info);
                    dealmethod.Add(methodinfoSource);
                }
                if (methodinfoSource.source == MethodInfoSourceEnum.InjectMethod)
                {
                    string methodfullname = Filter.GetMethodFullName(methodinfo);
                    Filter.NeedInjects.Add(methodfullname);
                }
            }


            return(funcLines);
        }
示例#4
0
        private string WriteRegisterDelegateConvertor(string method_delegate, LMethodInfo info)
        {
            bool   isAction         = info.m_ReturnString.ToLower().Contains("void");
            string paramstrings     = "";
            string paramTypestrings = "";
            int    index            = 0;

            foreach (var p in info.m_Params)
            {
                paramTypestrings += p.m_ParamString;
                paramstrings     += "arg" + index;
                if (index < info.m_Params.Count - 1)
                {
                    paramTypestrings += ",";
                    paramstrings     += ",";
                }

                index++;
            }
            if (!isAction)
            {
                if (info.m_Params.Count == 0)
                {
                    paramTypestrings = info.m_ReturnString;
                }
                else
                {
                    paramTypestrings += "," + info.m_ReturnString;
                }
            }

            //这里无论是注入生成还是脚本那边的都需要
            paramTypestrings = (string.IsNullOrEmpty(paramTypestrings) ? "" : ("<" + paramTypestrings + ">"));
            string regDelegate = "appDomain.DelegateManager.Register" + (isAction ? "Method" : "Function") + "Delegate" + paramTypestrings + "();\r\n";

            if (string.IsNullOrEmpty(paramTypestrings))
            {
                regDelegate = "";
            }

            string convertor = "";

            ////并且过滤掉system.action
            if (info.m_DelegateName.Contains("Action`") ||
                info.m_DelegateName.Contains("Func`") ||
                info.m_DelegateName.Contains("Predicate`"))
            {
            }
            else
            {
                string typeName = string.IsNullOrEmpty(info.m_DelegateName) ? ("LCLFunctionDelegate." + method_delegate) : method_delegate;
                convertor =
                    "   appDomain.DelegateManager.RegisterDelegateConvertor<" + typeName + ">((act) =>\r\n" +
                    "   {\r\n" +
                    "       return new " + typeName + "((" + paramstrings + ") =>\r\n" +
                    "       {\r\n" +
                    "       " + (isAction ? "" : "return ") + "((" + (isAction ? "Action" : "Func") + paramTypestrings + ")act)(" + paramstrings + ");\r\n" +
                    "       });\r\n" +
                    "   });\r\n";
            }
            return(regDelegate + convertor);
        }
示例#5
0
        private List <LMethodInfo> LoadAssembly(string assemblyName)
        {
            List <LMethodInfo> funcLines = new List <LMethodInfo>();

            m_Assembly = Assembly.LoadFile(assemblyName);
            var types    = m_Assembly.GetTypes();
            int methodId = 0;

            foreach (var type in types)
            {
                if (type.Namespace == null || !type.Namespace.Contains("LCL"))
                {
                    continue;
                }
                if (type.Name.Contains("LCLFunctionDelegate") ||
                    type.Name.Contains("LCLRegisterFunctionDelegate"))
                {
                    continue;
                }
                if (type.DeclaringType != null && (
                        type.DeclaringType.Name.Contains("LCLFunctionDelegate") ||
                        type.DeclaringType.Name.Contains("LCLRegisterFunctionDelegate")
                        ))
                {
                    continue;
                }
                var methodInfos = type.GetMethods(BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly);
                foreach (var methodinfo in methodInfos)
                {
                    //只处理本类的方法,派生方法不要
                    LMethodInfo info           = new LMethodInfo();
                    var         returnparamter = methodinfo.ReturnParameter;
                    info.m_ReturnString = returnparamter.ParameterType.ToString();
                    if (info.m_ReturnString.Contains("Void"))
                    {
                        info.m_ReturnString = "void";
                    }

                    var paramters = methodinfo.GetParameters();
                    if (paramters != null)
                    {
                        //添加this的object,每个委托都需要默认有一个
                        info.m_Params.Add(new ParamData()
                        {
                            m_ParamString = "System.Object", m_RefOut = RefOutArrayEnum.None
                        });
                        foreach (var pi in paramters)
                        {
                            ParamData paramdata = new ParamData();
                            if (pi.IsOut)
                            {
                                //暂时不支持out
                                paramdata.m_RefOut = RefOutArrayEnum.Out;
                                continue;
                            }
                            else if (pi.ParameterType.IsByRef)
                            {
                                //暂时不支持ref
                                paramdata.m_RefOut = RefOutArrayEnum.Ref;
                                continue;
                            }
                            else if (pi.ParameterType.IsArray)
                            {
                                paramdata.m_RefOut = RefOutArrayEnum.Array;
                            }


                            paramdata.m_ParamString = pi.ParameterType.ToString().Replace("&", "");
                            info.m_Params.Add(paramdata);
                        }
                    }
                    if (!funcLines.Exists((oldInfo) => { return(IsEqualLMethodInfo(oldInfo, info)); }))
                    {
                        funcLines.Add(info);
                    }
                }
            }

            return(funcLines);
        }
示例#6
0
        private List <LMethodInfo> LoadAssembly(string assemblyName)
        {
            List <LMethodInfo> funcLines = new List <LMethodInfo>();

            m_Assembly = Assembly.LoadFile(assemblyName);
            var types    = m_Assembly.GetTypes();
            int methodId = 0;

            Filter.NeedInjects.Clear();

            foreach (var type in types)
            {
                if (type.Namespace == null || !type.Namespace.Contains("LCL"))
                {
                    continue;
                }
                if (!Filter.FilterType(type))
                {
                    continue;
                }
                if (type.Name.Contains("LCLFunctionDelegate") ||
                    type.Name.Contains("LCLRegisterFunctionDelegate"))
                {
                    continue;
                }
                if (type.DeclaringType != null && (
                        type.DeclaringType.Name.Contains("LCLFunctionDelegate") ||
                        type.DeclaringType.Name.Contains("LCLRegisterFunctionDelegate")
                        ))
                {
                    continue;
                }
                Filter.NeedInjects.Add(type.FullName);

                var methodInfos = type.GetMethods(BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly);
                foreach (var methodinfo in methodInfos)
                {
                    if (!Filter.FilterMethod(methodinfo))
                    {
                        continue;
                    }

                    //只处理本类的方法,派生方法不要
                    LMethodInfo info           = new LMethodInfo();
                    var         returnparamter = methodinfo.ReturnParameter;
                    info.m_ReturnString = returnparamter.ParameterType.ToString();
                    if (info.m_ReturnString.Contains("Void"))
                    {
                        info.m_ReturnString = "void";
                    }

                    var paramters = methodinfo.GetParameters();
                    if (paramters != null)
                    {
                        //添加this的object,每个委托都需要默认有一个
                        info.m_Params.Add(new ParamData()
                        {
                            m_ParamString = "System.Object", m_RefOut = RefOutArrayEnum.None
                        });
                        foreach (var pi in paramters)
                        {
                            ParamData paramdata = new ParamData();
                            if (pi.IsOut)
                            {
                                //暂时不支持out
                                paramdata.m_RefOut = RefOutArrayEnum.Out;
                                continue;
                            }
                            else if (pi.ParameterType.IsByRef)
                            {
                                //暂时不支持ref
                                paramdata.m_RefOut = RefOutArrayEnum.Ref;
                                continue;
                            }
                            else if (pi.ParameterType.IsArray)
                            {
                                paramdata.m_RefOut = RefOutArrayEnum.Array;
                            }


                            paramdata.m_ParamString = pi.ParameterType.ToString().Replace("&", "");
                            info.m_Params.Add(paramdata);
                        }
                    }

                    string returnstr = methodinfo.ReturnType.FullName;
                    string name      = methodinfo.DeclaringType.FullName + "::" + methodinfo.Name;
                    string paramstr  = "";
                    int    count     = methodinfo.GetParameters().Length;
                    int    index     = 1;

                    foreach (var param in methodinfo.GetParameters())
                    {
                        string split = index++ == count ? "" : ",";
                        paramstr += param.ParameterType.FullName + split;
                    }
                    string methodfullname = returnstr + " " + name + "(" + paramstr + ")";

                    Filter.NeedInjects.Add(methodfullname);

                    if (!funcLines.Exists((oldInfo) => { return(IsEqualLMethodInfo(oldInfo, info)); }))
                    {
                        funcLines.Add(info);
                    }
                }
            }

            return(funcLines);
        }