Skip to content

Commit

Permalink
Improve custom member info provider test case.
Browse files Browse the repository at this point in the history
  • Loading branch information
koculu committed Jan 1, 2024
1 parent 1422aca commit e81d324
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions src/Topaz.Test/AwaitTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -205,14 +205,21 @@ class CustomMemberInfoProvider : IMemberInfoProvider
{
public MemberInfo[] GetInstanceMembers(object instance, string memberName)
{
if (memberName == "MoveNextAsync")
// Handle special case for auto generated async enumerators or
// explicitly defined interface members using interface map.
// MoveNextAsync is not accessible through the instance's type
// and it is not public.
// https://github.com/dotnet/roslyn/issues/71406

var type = instance.GetType();
var interfaces = type.GetTypeInfo().GetInterfaces();
var list = new List<MemberInfo>();
foreach (var itype in interfaces)
{
// Handle special case for auto generated async enumerators.
// MoveNextAsync is not accessible through its name and it is not public.
// https://github.com/dotnet/roslyn/issues/71406
return instance.GetType().GetMember("System.Collections.Generic.IAsyncEnumerator<System.Int32>.MoveNextAsync", BindingFlags.NonPublic | BindingFlags.Instance);
list.AddRange(itype.GetMember(memberName, BindingFlags.Public | BindingFlags.Instance));
}
return instance.GetType().GetMember(memberName, BindingFlags.Public | BindingFlags.Instance);
list.AddRange(type.GetMember(memberName, BindingFlags.Public | BindingFlags.Instance));
return list.ToArray();
}

public MemberInfo[] GetStaticMembers(Type type, string memberName)
Expand Down

0 comments on commit e81d324

Please sign in to comment.