示例#1
0
        private void ParseTypes(Type[] types, List <MethodInfoSource> list, bool isDelegate = false)
        {
            foreach (var type in types)
            {
                MethodInfoSourceEnum source = MethodInfoSourceEnum.InjectMethod;
                if (!isDelegate)
                {
                    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;
                    }
                }
                //方法
                var TotalMethodInfos = new List <MethodInfo>();
                if (type.BaseType == typeof(MulticastDelegate) || type.BaseType == typeof(Delegate))
                {
                    source = MethodInfoSourceEnum.Delegate;
                    //将委托中的Invoke进行转化,其他函数忽略
                    TotalMethodInfos.AddRange(type.GetMethods().ToList().FindAll((_m) => _m.Name == "Invoke"));
                }
                else
                {
                    if (type.Name == "Timer")
                    {
                        int a = 0;
                    }
                    //字段中含有的委托
                    List <Type> fieldTypes   = new List <Type>();
                    var         fieldMethods = type.GetFields(BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance | BindingFlags.GetField | BindingFlags.DeclaredOnly);
                    foreach (var field in fieldMethods)
                    {
                        Type fieldType = field.FieldType;
                        if (fieldType.BaseType == typeof(MulticastDelegate) || fieldType.BaseType == typeof(Delegate))
                        {
                            fieldTypes.Add(fieldType);
                        }
                    }
                    ParseTypes(fieldTypes.ToArray(), list, true);

                    //属性中含有委托
                    List <Type> propertyTypes   = new List <Type>();
                    var         propertyMethods = type.GetProperties(BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance | BindingFlags.GetProperty | BindingFlags.DeclaredOnly);
                    foreach (var property in propertyMethods)
                    {
                        Type propertyType = property.PropertyType;
                        if (propertyType.BaseType == typeof(MulticastDelegate) || propertyType.BaseType == typeof(Delegate))
                        {
                            fieldTypes.Add(propertyType);
                        }
                    }
                    ParseTypes(propertyTypes.ToArray(), list, true);

                    //普通方法
                    var methodInfos = type.GetMethods(BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly);
                    TotalMethodInfos.AddRange(methodInfos);
                }

                foreach (var methodinfo in TotalMethodInfos)
                {
                    if (CheckMethod(methodinfo, list))
                    {
                        MethodInfoSource mis = new MethodInfoSource();
                        mis.mothodInfo = methodinfo;
                        mis.source     = source;
                        list.Add(mis);
                    }
                }
            }
        }
示例#2
0
        private void ParseTypes(Type declareType, Type[] types, List <MethodInfoSource> list, bool isDelegate = false)
        {
            foreach (var type in types)
            {
                MethodInfoSourceEnum source = MethodInfoSourceEnum.InjectMethod;
                if (!isDelegate)
                {
                    if (Filter.DelegateTypeFilter(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;
                    }
                }
                //方法
                var TotalMethodInfos = new List <MethodInfo>();
                if (type.BaseType == typeof(MulticastDelegate) || type.BaseType == typeof(Delegate))
                {
                    source = MethodInfoSourceEnum.Delegate;
                    if (type.FullName.Contains("Predicate`"))
                    {
                        string declareName = declareType == null ? type.FullName : declareType.FullName + "里面的" + type.FullName;
                        UnityEngine.Debug.LogError("脚本引擎好像是不支持Predicate的,请检查相关函数是否有导出到热更新里面使用:" + declareName);
                    }
                    else if (type.FullName.Contains("Converter`"))
                    {
                        string declareName = declareType == null ? type.FullName : declareType.FullName + "里面的" + type.FullName;
                        UnityEngine.Debug.LogError("脚本引擎好像是不支持Converter的,请检查相关函数是否有导出到热更新里面使用:" + declareName);
                    }

                    //将委托中的Invoke进行转化,其他函数忽略
                    TotalMethodInfos.AddRange(type.GetMethods().ToList().FindAll(
                                                  (_m) =>
                    {
                        return(_m.Name == "Invoke");
                    }));
                }
                else
                {
                    //字段中含有的委托
                    List <Type> fieldTypes   = new List <Type>();
                    var         fieldMethods = type.GetFields(BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance | BindingFlags.GetField | BindingFlags.DeclaredOnly);
                    foreach (var field in fieldMethods)
                    {
                        Type fieldType = field.FieldType;
                        if (fieldType.BaseType == typeof(MulticastDelegate) || fieldType.BaseType == typeof(Delegate))
                        {
                            fieldTypes.Add(fieldType);
                        }
                    }
                    ParseTypes(type, fieldTypes.ToArray(), list, true);

                    //属性中含有委托
                    List <Type> propertyTypes   = new List <Type>();
                    var         propertyMethods = type.GetProperties(BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance | BindingFlags.GetProperty | BindingFlags.DeclaredOnly);
                    foreach (var property in propertyMethods)
                    {
                        Type propertyType = property.PropertyType;
                        if (propertyType.BaseType == typeof(MulticastDelegate) || propertyType.BaseType == typeof(Delegate))
                        {
                            fieldTypes.Add(propertyType);
                        }
                    }
                    ParseTypes(type, propertyTypes.ToArray(), list, true);

                    //普通方法
                    var methodInfos = type.GetMethods(BindingFlags.Static | BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly);
                    TotalMethodInfos.AddRange(methodInfos);
                }

                foreach (var methodinfo in TotalMethodInfos)
                {
                    if (CheckMethod(methodinfo, list))
                    {
                        MethodInfoSource mis = new MethodInfoSource();
                        mis.mothodInfo = methodinfo;
                        mis.source     = source;
                        list.Add(mis);
                    }
                }
            }
        }