public static void Bind(string dllPath) { var dir = Path.GetDirectoryName(dllPath); DefaultAssemblyResolver resolver = new DefaultAssemblyResolver(); resolver.AddSearchDirectory(dir); ReaderParameters parameters = new ReaderParameters() { AssemblyResolver = resolver, ReadSymbols = false, }; ModuleDefinition module = ModuleDefinition.ReadModule(dllPath, parameters); moduleSet.Add(module); var moduleTypes = new HashSet <TypeReference>(module.Types); foreach (TypeDefinition type in moduleTypes) { //Utils.Log(type.FullName); if (!CUtils.Filter(type)) { Utils.Log("ignor type:" + type.FullName); continue; } foreach (var method in type.Methods) { if (CUtils.IsIcall(method)) { if (!CUtils.Filter(method)) { Utils.Log("ignor icall:" + method.FullName); continue; } ICallGenerater.AddMethod(method); } else if (CUtils.IsEventCallback(method) && !method.IsConstructor) { if (!CUtils.Filter(method)) { Utils.Log("ignor event:" + method.FullName); continue; } EventGenerater.AddMethod(method); } } } }
public static void TestBind(string dllPath) { if (!EnableTest) { return; } sw.WriteLine("// >>>> " + Path.GetFileName(dllPath)); checkSet.Clear(); var dir = Path.GetDirectoryName(dllPath); DefaultAssemblyResolver resolver = new DefaultAssemblyResolver(); resolver.AddSearchDirectory(dir); ReaderParameters parameters = new ReaderParameters() { AssemblyResolver = resolver, ReadSymbols = false, }; ModuleDefinition module = ModuleDefinition.ReadModule(dllPath, parameters); var moduleTypes = new HashSet <TypeDefinition>(module.Types); foreach (TypeDefinition type in moduleTypes) { if (!CUtils.Filter(type)) { // Console.WriteLine("ignor type:" + type.FullName); continue; } foreach (var method in type.Methods) { if (CUtils.IsIcall(method)) { if (!CUtils.Filter(method)) { //Console.WriteLine("ignor icall:" + method.FullName); //checkSet.Add(method.FullName + " // <Icall"); continue; } CheckMethod(method); //ICallGenerater.AddMethod(method); } //else if (CUtils.IsEventCallback(method) && !method.IsConstructor) else if (CUtils.IsNativeCallback(method) && !method.IsConstructor) { if (!CUtils.Filter(method)) { // Console.WriteLine("ignor event:" + method.FullName); // checkSet.Add(method.FullName + " // <Event"); continue; } CheckMethod(method); // EventGenerater.AddMethod(method); } } } foreach (var c in checkSet) { sw.WriteLine($"public {c} T_{index};"); index++; } }