Skip to content
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

Compare references correctly to avoid AOT error. Fix #400 #401

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions Source/VSProj/Src/Tools/CodeTranslator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,17 @@ int addInternString(string str, MethodDefinition caller)
return id;
}

private static bool IsMemberReferenceEqual(MemberReference t1, MemberReference t2)
{
return t1.FullName == t2.FullName &&
t1.Module.Assembly.FullName == t2.Module.Assembly.FullName;
}

private static bool IsAsyncMethodBuilderMethodEqual(GenericInstanceMethod m1, GenericInstanceMethod m2)
{
return IsMemberReferenceEqual(m1.GenericArguments[0], m2.GenericArguments[0]) && m1.DeclaringType?.FullName == m2.DeclaringType?.FullName;
}

//原生方法的引用
int addExternMethod(MethodReference callee, MethodDefinition caller)
{
Expand All @@ -276,8 +287,7 @@ int addExternMethod(MethodReference callee, MethodDefinition caller)

if (callee.Name == "AwaitUnsafeOnCompleted")
{

if (!awaitUnsafeOnCompletedMethods.Any(m => ((GenericInstanceMethod)callee).GenericArguments[0] == ((GenericInstanceMethod)m).GenericArguments[0]))
if (awaitUnsafeOnCompletedMethods.All(m => !IsAsyncMethodBuilderMethodEqual((GenericInstanceMethod)callee, (GenericInstanceMethod)m)))
{
awaitUnsafeOnCompletedMethods.Add(callee);
}
Expand Down