-
Notifications
You must be signed in to change notification settings - Fork 657
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
修复跨域适配器生成代码的 bug #750
Open
m1stm4o
wants to merge
5
commits into
Ourpalm:master
Choose a base branch
from
m1stm4o:fix_adapter_generator
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
修复跨域适配器生成代码的 bug #750
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
e764b39
fix 生成的适配器中含有未知类型 TResult
m1stm4o d7ee161
fix 生成的适配器中函数参数类型列表包含了返回类型
m1stm4o 98ca3f5
fix 生成的适配器中 out 参数初始值类型字符串不对
m1stm4o 77273bb
对于 protected 虚函数,返回类型可以包含 protected 内嵌类
m1stm4o ceb3265
fix 生成适配器时基类的 Property 的 get set 访问修饰符不一致时生成的代码不正确
m1stm4o File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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<MethodInfo> vi | |
} | ||
else | ||
{ | ||
pInfo.Modifier = modifier; | ||
pInfo.OverrideString = overrideStr; | ||
} | ||
if (!i.IsAbstract) | ||
|
@@ -221,10 +221,12 @@ static void GenerateCrossBindingMethodBody(StringBuilder sb, List<MethodInfo> vi | |
{ | ||
if (isGetter) | ||
{ | ||
pInfo.GetterModifier = modifier; | ||
pInfo.GetterBody = sb.ToString(); | ||
} | ||
else | ||
{ | ||
pInfo.SettingModifier = modifier; | ||
pInfo.SettingBody = sb.ToString(); | ||
} | ||
sb = oriBuilder; | ||
|
@@ -243,19 +245,22 @@ static void GenerateCrossBindingMethodBody(StringBuilder sb, List<MethodInfo> 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(" }"); | ||
|
||
} | ||
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;"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unity2018以前的版本不支持default关键字,只支持default(T) |
||
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)); | ||
} | ||
} | ||
} | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
能否提供一个生成不正确的具体例子