From e81d324bcf84bcb4100b6050128a6b9358084119 Mon Sep 17 00:00:00 2001 From: Ahmed Yasin Koculu Date: Mon, 1 Jan 2024 02:44:09 +0100 Subject: [PATCH] Improve custom member info provider test case. --- src/Topaz.Test/AwaitTests.cs | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/src/Topaz.Test/AwaitTests.cs b/src/Topaz.Test/AwaitTests.cs index c1ca6cc..3e04a25 100644 --- a/src/Topaz.Test/AwaitTests.cs +++ b/src/Topaz.Test/AwaitTests.cs @@ -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(); + 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.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)