[英]Check if the method uses PInvoke
反正有沒有檢查方法是否使用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
}
}
您可以使用此擴展方法:
public static bool IsPinvoke(this MethodBase method)
{
return method.Attributes.HasFlag(MethodAttributes.PinvokeImpl);
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.