diff --git a/ILRuntime/Runtime/Enviorment/CrossBindingCodeGenerator.cs b/ILRuntime/Runtime/Enviorment/CrossBindingCodeGenerator.cs index 73bde9d2..4023439e 100644 --- a/ILRuntime/Runtime/Enviorment/CrossBindingCodeGenerator.cs +++ b/ILRuntime/Runtime/Enviorment/CrossBindingCodeGenerator.cs @@ -18,7 +18,8 @@ class PropertyGenerateInfo public Type ReturnType; public string GetterBody; public string SettingBody; - public string Modifier; + public string GetterModifier; + public string SettingModifier; public string OverrideString; } @@ -188,7 +189,6 @@ static void GenerateCrossBindingMethodBody(StringBuilder sb, List vi } else { - pInfo.Modifier = modifier; pInfo.OverrideString = overrideStr; } if (!i.IsAbstract) @@ -221,10 +221,12 @@ static void GenerateCrossBindingMethodBody(StringBuilder sb, List vi { if (isGetter) { + pInfo.GetterModifier = modifier; pInfo.GetterBody = sb.ToString(); } else { + pInfo.SettingModifier = modifier; pInfo.SettingBody = sb.ToString(); } sb = oriBuilder; @@ -243,11 +245,13 @@ static void GenerateCrossBindingMethodBody(StringBuilder sb, List vi string clsName, realClsName; bool isByRef; pInfo.ReturnType.GetClassName(out clsName, out realClsName, out isByRef, true); - sb.AppendLine(string.Format(" {0} {3}{1} {2}", pInfo.Modifier, realClsName, pInfo.Name, pInfo.OverrideString)); + var modifier = pInfo.GetterModifier == "public" || string.IsNullOrEmpty(pInfo.SettingModifier) ? pInfo.GetterModifier : pInfo.SettingModifier; + sb.AppendLine(string.Format(" {0} {3}{1} {2}", modifier, realClsName, pInfo.Name, pInfo.OverrideString)); sb.AppendLine(" {"); if (!string.IsNullOrEmpty(pInfo.GetterBody)) { - sb.AppendLine(" get"); + if (pInfo.GetterModifier == modifier) sb.AppendLine(" get"); + else sb.AppendLine($" {pInfo.GetterModifier} get"); sb.AppendLine(" {"); sb.AppendLine(pInfo.GetterBody); sb.AppendLine(" }"); @@ -255,7 +259,8 @@ static void GenerateCrossBindingMethodBody(StringBuilder sb, List vi } if (!string.IsNullOrEmpty(pInfo.SettingBody)) { - sb.AppendLine(" set"); + if (pInfo.SettingModifier == modifier) sb.AppendLine(" set"); + else sb.AppendLine($" {pInfo.SettingModifier} set"); sb.AppendLine(" {"); sb.AppendLine(pInfo.SettingBody); sb.AppendLine(" }"); @@ -322,7 +327,7 @@ static bool ShouldSkip(MethodInfo info) var returnType = info.ReturnType; if (returnType.IsByRef) returnType = returnType.GetElementType(); - if (returnType.IsNotPublic || returnType.IsNested && !returnType.IsNestedPublic) + if (returnType.IsNotPublic || returnType.IsNested && !returnType.IsNestedPublic && !returnType.IsNestedFamily && !returnType.IsNestedFamORAssem) return true; return false; @@ -373,15 +378,6 @@ static string GetParametersTypeString(ParameterInfo[] param, Type returnType) if (isByRef) sb.Append(".MakeByRefType()"); } - if (returnType != typeof(void)) - { - if (!first) - sb.Append(", "); - string clsName, realClsName; - bool isByRef; - returnType.GetClassName(out clsName, out realClsName, out isByRef, true); - sb.Append(realClsName); - } return sb.ToString(); } @@ -531,7 +527,7 @@ static void GenerateCrossBindingMethodClass(StringBuilder sb, string funcName, i sb.AppendLine(" }"); if (hasReturn) sb.AppendLine(@" else - return default(TResult);"); + return default;"); sb.AppendLine(@" } public override void Invoke(ILTypeInstance instance) @@ -602,7 +598,8 @@ static void GenInitParams(StringBuilder sb, ParameterInfo[] param) { if (p.IsOut) { - sb.AppendLine(string.Format(" {0} = default({1});", p.Name, p.ParameterType.GetElementType().FullName)); + p.ParameterType.GetClassName(out var clsName, out var realClsName, out var isByRef, true); + sb.AppendLine(string.Format(" {0} = default({1});", p.Name, realClsName)); } } }