开发者

Detecting DllImportAttribute and its data in an assembly

开发者 https://www.devze.com 2023-04-09 20:34 出处:网络
I am trying to find (at runtime) the the the p/invokes along with their information: 1) Dll name 2) EntryPoint.

I am trying to find (at runtime) the the the p/invokes along with their information: 1) Dll name 2) EntryPoint.

I tried something like this: Assembly.GetExecutingAssembly().GetCustomAttributesData(); but for some reason I dont see the type DllImportAttribute listed there although I have a开发者_C百科 p/invoke in that assembly.

I am pretty sure am missing something here. Any ideas?

Thanks!


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,
               };
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号