From 00e5ed737b83aa8426838577c67611b33c7d7a6d Mon Sep 17 00:00:00 2001 From: m1stm4o <16450904+m1stm4o@users.noreply.github.com> Date: Tue, 28 Mar 2023 23:21:34 +0800 Subject: [PATCH] =?UTF-8?q?=E9=81=BF=E5=85=8D=20Action=20=E5=92=8C=20Func?= =?UTF-8?q?=20=E7=B1=BB=E5=9E=8B=E7=9A=84=E5=A7=94=E6=89=98=E7=94=9F?= =?UTF-8?q?=E6=88=90=20Convertor=20=E6=B3=A8=E5=86=8C=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=EF=BC=8C=E5=87=8F=E5=B0=91=E4=BB=A3=E7=A0=81=E9=87=8F=EF=BC=8C?= =?UTF-8?q?=E8=8A=82=E7=9C=81=E8=B0=83=E7=94=A8=E6=80=A7=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../CLRBinding/BindingCodeGenerator.cs | 111 +++++++++--------- 1 file changed, 57 insertions(+), 54 deletions(-) diff --git a/ILRuntime/Runtime/CLRBinding/BindingCodeGenerator.cs b/ILRuntime/Runtime/CLRBinding/BindingCodeGenerator.cs index 8aafdebb..67689dc0 100755 --- a/ILRuntime/Runtime/CLRBinding/BindingCodeGenerator.cs +++ b/ILRuntime/Runtime/CLRBinding/BindingCodeGenerator.cs @@ -725,29 +725,15 @@ public static void Register(ILRuntime.Runtime.Enviorment.AppDomain app) sb.AppendLine(); } - sb.Append(" app.DelegateManager.RegisterDelegateConvertor<"); - sb.Append(realClsName); - sb.AppendLine(">((act) =>"); - sb.AppendLine(" {"); - sb.Append(" return new "); - sb.Append(realClsName); - sb.Append("(("); - first = true; - foreach (var j in miParameters) + if (!realClsName.StartsWith("System.Action<", StringComparison.Ordinal) && !realClsName.StartsWith("System.Func<", StringComparison.Ordinal)) { - if (first) - { - first = false; - } - else - sb.Append(", "); - sb.Append(j.Name); - } - sb.AppendLine(") =>"); - sb.AppendLine(" {"); - if (mi.ReturnType != typeof(void)) - { - sb.Append(" return ((Func<"); + sb.Append(" app.DelegateManager.RegisterDelegateConvertor<"); + sb.Append(realClsName); + sb.AppendLine(">((act) =>"); + sb.AppendLine(" {"); + sb.Append(" return new "); + sb.Append(realClsName); + sb.Append("(("); first = true; foreach (var j in miParameters) { @@ -757,21 +743,54 @@ public static void Register(ILRuntime.Runtime.Enviorment.AppDomain app) } else sb.Append(", "); - j.ParameterType.GetClassName(out paramClsName, out paramRealClsName, out paramIsByRef); + sb.Append(j.Name); + } + sb.AppendLine(") =>"); + sb.AppendLine(" {"); + if (mi.ReturnType != typeof(void)) + { + sb.Append(" return ((Func<"); + first = true; + foreach (var j in miParameters) + { + if (first) + { + first = false; + } + else + sb.Append(", "); + j.ParameterType.GetClassName(out paramClsName, out paramRealClsName, out paramIsByRef); + sb.Append(paramRealClsName); + } + if (!first) + sb.Append(", "); + mi.ReturnType.GetClassName(out paramClsName, out paramRealClsName, out paramIsByRef); sb.Append(paramRealClsName); + sb.Append(">)act)("); } - if (!first) - sb.Append(", "); - mi.ReturnType.GetClassName(out paramClsName, out paramRealClsName, out paramIsByRef); - sb.Append(paramRealClsName); - sb.Append(">)act)("); - } - else - { - if (miParameters.Length != 0) - sb.Append(" ((Action<"); else - sb.Append(" ((Action"); + { + if (miParameters.Length != 0) + sb.Append(" ((Action<"); + else + sb.Append(" ((Action"); + first = true; + foreach (var j in miParameters) + { + if (first) + { + first = false; + } + else + sb.Append(", "); + j.ParameterType.GetClassName(out paramClsName, out paramRealClsName, out paramIsByRef); + sb.Append(paramRealClsName); + } + if (miParameters.Length != 0) + sb.Append(">)act)("); + else + sb.Append(")act)("); + } first = true; foreach (var j in miParameters) { @@ -781,28 +800,12 @@ public static void Register(ILRuntime.Runtime.Enviorment.AppDomain app) } else sb.Append(", "); - j.ParameterType.GetClassName(out paramClsName, out paramRealClsName, out paramIsByRef); - sb.Append(paramRealClsName); - } - if (miParameters.Length != 0) - sb.Append(">)act)("); - else - sb.Append(")act)("); - } - first = true; - foreach (var j in miParameters) - { - if (first) - { - first = false; + sb.Append(j.Name); } - else - sb.Append(", "); - sb.Append(j.Name); + sb.AppendLine(");"); + sb.AppendLine(" });"); + sb.AppendLine(" });"); } - sb.AppendLine(");"); - sb.AppendLine(" });"); - sb.AppendLine(" });"); sb.AppendLine(" }"); sb.AppendLine(" }");