[fix] 修复计算 MonoPInvokeCallback的CallingConvention时,如果delegate在其他程序集中定义,会被错误当作Winapi,导致wrapper签名计算错误的bug

main
walon 2024-05-30 12:26:48 +08:00
parent 170f13082e
commit 846d7103a3
1 changed files with 3 additions and 3 deletions

View File

@ -93,7 +93,7 @@ namespace HybridCLR.Editor.ReversePInvokeWrap
TypeDef delegateTypeDef; TypeDef delegateTypeDef;
if (delegateTypeSig is ClassSig classSig) if (delegateTypeSig is ClassSig classSig)
{ {
delegateTypeDef = classSig.TypeDef; delegateTypeDef = classSig.TypeDefOrRef.ResolveTypeDefThrow();
} }
else if (delegateTypeSig is GenericInstSig genericInstSig) else if (delegateTypeSig is GenericInstSig genericInstSig)
{ {
@ -101,12 +101,12 @@ namespace HybridCLR.Editor.ReversePInvokeWrap
} }
else else
{ {
throw new NotSupportedException($"Unsupported delegate type {delegateTypeSig.GetType()}"); delegateTypeDef = null;
} }
if (delegateTypeDef == null) if (delegateTypeDef == null)
{ {
return CallingConvention.Winapi; throw new NotSupportedException($"Unsupported delegate type {delegateTypeSig.GetType()}");
} }
var attr = delegateTypeDef.CustomAttributes.FirstOrDefault(ca => ca.AttributeType.FullName == "System.Runtime.InteropServices.UnmanagedFunctionPointerAttribute"); var attr = delegateTypeDef.CustomAttributes.FirstOrDefault(ca => ca.AttributeType.FullName == "System.Runtime.InteropServices.UnmanagedFunctionPointerAttribute");
if (attr == null) if (attr == null)