是否有检查方法是否使用 PInvoke 的方法? 我正在使用 MethodBase 遍历程序集中的所有方法,但我想检查该方法是否正在使用 PInvoke。 这是我正在使用的代码:
foreach (MethodBase bases in mtd.GetType().GetMethods())
{
//check if the method is using pinvoke
}
另外,如果可能的话,有什么方法可以检查正在使用的 DLL 和正在调用的函数/入口点?
最佳答案
你可以检查一个方法是否用DllImportAttribute修饰.如果是这样,它正在使用 PInvoke。
foreach (MethodBase methodBase in mtd.GetType().GetMethods())
{
if (methodBase.CustomAttributes.Any(cad => cad.AttributeType == typeof(DllImportAttribute))
{
// Method is using PInvoke
}
}
关于c# - 检查方法是否使用 PInvoke,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12677230/