|
10 | 10 | using System; |
11 | 11 | using UnityEngine; |
12 | 12 | using XLua; |
| 13 | +//using System.Reflection; |
| 14 | +//using System.Linq; |
13 | 15 |
|
14 | 16 | //配置的详细介绍请看Doc下《XLua的配置.doc》 |
15 | 17 | public static class ExampleGenConfig |
@@ -89,4 +91,60 @@ public static class ExampleGenConfig |
89 | 91 | new List<string>(){"System.IO.DirectoryInfo", "Create", "System.Security.AccessControl.DirectorySecurity"}, |
90 | 92 | new List<string>(){"UnityEngine.MonoBehaviour", "runInEditMode"}, |
91 | 93 | }; |
| 94 | + |
| 95 | + //static bool hasGenericParameter(Type type) |
| 96 | + //{ |
| 97 | + // if (type.IsGenericTypeDefinition) return true; |
| 98 | + // if (type.IsGenericParameter) return true; |
| 99 | + // if (type.IsByRef || type.IsArray) |
| 100 | + // { |
| 101 | + // return hasGenericParameter(type.GetElementType()); |
| 102 | + // } |
| 103 | + // if (type.IsGenericType) |
| 104 | + // { |
| 105 | + // foreach (var typeArg in type.GetGenericArguments()) |
| 106 | + // { |
| 107 | + // if (hasGenericParameter(typeArg)) |
| 108 | + // { |
| 109 | + // return true; |
| 110 | + // } |
| 111 | + // } |
| 112 | + // } |
| 113 | + // return false; |
| 114 | + //} |
| 115 | + |
| 116 | + //// 配置某Assembly下所有涉及到的delegate到CSharpCallLua下,Hotfix下拿不准那些delegate需要适配到lua function可以这么配置 |
| 117 | + //[CSharpCallLua] |
| 118 | + //static IEnumerable<Type> AllDelegate |
| 119 | + //{ |
| 120 | + // get |
| 121 | + // { |
| 122 | + // BindingFlags flag = BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public; |
| 123 | + // List<Type> allTypes = new List<Type>(); |
| 124 | + // var allAssemblys = new Assembly[] |
| 125 | + // { |
| 126 | + // Assembly.Load("Assembly-CSharp") |
| 127 | + // }; |
| 128 | + // foreach (var t in (from assembly in allAssemblys from type in assembly.GetTypes() select type)) |
| 129 | + // { |
| 130 | + // var p = t; |
| 131 | + // while (p != null) |
| 132 | + // { |
| 133 | + // allTypes.Add(p); |
| 134 | + // p = p.BaseType; |
| 135 | + // } |
| 136 | + // } |
| 137 | + // allTypes = allTypes.Distinct().ToList(); |
| 138 | + // var allMethods = from type in allTypes |
| 139 | + // from method in type.GetMethods(flag) |
| 140 | + // select method; |
| 141 | + // var returnTypes = from method in allMethods |
| 142 | + // select method.ReturnType; |
| 143 | + // var paramTypes = allMethods.SelectMany(m => m.GetParameters()).Select(pinfo => pinfo.ParameterType.IsByRef ? pinfo.ParameterType.GetElementType() : pinfo.ParameterType); |
| 144 | + // var fieldTypes = from type in allTypes |
| 145 | + // from field in type.GetFields(flag) |
| 146 | + // select field.FieldType; |
| 147 | + // return (returnTypes.Concat(paramTypes).Concat(fieldTypes)).Where(t => t.BaseType == typeof(MulticastDelegate) && !hasGenericParameter(t)).Distinct(); |
| 148 | + // } |
| 149 | + //} |
92 | 150 | } |
0 commit comments