[change] validate unsupported parameter type(.e.g string) in PInvoke signature when generate MethodBridge file
parent
52f25bdb2a
commit
ddc3332958
|
|
@ -26,6 +26,30 @@ namespace HybridCLR.Editor.MethodBridge
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static bool IsSupportedPInvokeTypeSig(TypeSig typeSig)
|
||||||
|
{
|
||||||
|
typeSig = typeSig.RemovePinnedAndModifiers();
|
||||||
|
if (typeSig.IsByRef)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
switch (typeSig.ElementType)
|
||||||
|
{
|
||||||
|
case ElementType.SZArray:
|
||||||
|
case ElementType.Array:
|
||||||
|
//case ElementType.Class:
|
||||||
|
case ElementType.String:
|
||||||
|
//case ElementType.Object:
|
||||||
|
return false;
|
||||||
|
default: return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static bool IsSupportedPInvokeMethodSignature(MethodSig methodSig)
|
||||||
|
{
|
||||||
|
return IsSupportedPInvokeTypeSig(methodSig.RetType) && methodSig.Params.All(p => IsSupportedPInvokeTypeSig(p));
|
||||||
|
}
|
||||||
|
|
||||||
public void Run()
|
public void Run()
|
||||||
{
|
{
|
||||||
foreach (var mod in _rootModules)
|
foreach (var mod in _rootModules)
|
||||||
|
|
@ -36,6 +60,10 @@ namespace HybridCLR.Editor.MethodBridge
|
||||||
{
|
{
|
||||||
if (method.IsPinvokeImpl)
|
if (method.IsPinvokeImpl)
|
||||||
{
|
{
|
||||||
|
if (!IsSupportedPInvokeMethodSignature(method.MethodSig))
|
||||||
|
{
|
||||||
|
throw new Exception($"PInvoke method {method.FullName} has unsupported parameter or return type. Please check the method signature.");
|
||||||
|
}
|
||||||
_pinvokeMethodSignatures.Add(new CallNativeMethodSignatureInfo { MethodSig = method.MethodSig });
|
_pinvokeMethodSignatures.Add(new CallNativeMethodSignatureInfo { MethodSig = method.MethodSig });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue