开发者

Detecting DllImportAttribute and its data in an assembly

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜