检测程序集中的DllImportAttribute及其数据

本文关键字:数据 DllImportAttribute 程序 程序集 集中 检测 | 更新日期: 2023-09-27 18:10:04

我试图找到(在运行时)的p/调用与他们的信息:1)Dll名称2)EntryPoint。

我尝试了这样的东西:Assembly.GetExecutingAssembly().GetCustomAttributesData();,但由于某种原因,我没有看到类型DllImportAttribute列出,虽然我有一个p/调用在该程序集。

我很确定我遗漏了一些东西。什么好主意吗?

谢谢!

检测程序集中的DllImportAttribute及其数据

var pinvokes = from type in Assembly.GetExecutingAssembly().GetTypes()
               from method in type.GetMethods(BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic)
               let dllImport = (DllImportAttribute)method.GetCustomAttributes(typeof(DllImportAttribute), false).FirstOrDefault()
               where dllImport != null
               select new
               {
                   DllName = dllImport.Value,
                   EntryPoint = dllImport.EntryPoint,
               };