Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
如何使用反射从程序集中枚举所有 DLLImport?
循环遍历每个类中的每个方法,并检查是否GetCustomAttributes(typeof(DllImportAttribute))返回任何内容。
GetCustomAttributes(typeof(DllImportAttribute))
assembly.GetTypes() .SelectMany(t => t.GetMethods(flags)) .Where(m => Attribute.GetCustomAttribute(m, typeof(DllImportAttribute)) != null);