Skip to content

Restrict ConditionalMemberKinds to reflect what ConditionalTestDiscoverer reflects on#16739

Merged
MichalStrehovsky merged 1 commit intomainfrom
MichalStrehovsky-patch-1
Apr 24, 2026
Merged

Restrict ConditionalMemberKinds to reflect what ConditionalTestDiscoverer reflects on#16739
MichalStrehovsky merged 1 commit intomainfrom
MichalStrehovsky-patch-1

Conversation

@MichalStrehovsky
Copy link
Copy Markdown
Member

Matching code is this:

internal static Func<bool> LookupConditionalMember(Type t, string name)
{
if (t == null || name == null)
return null;
TypeInfo ti = t.GetTypeInfo();
MethodInfo mi = ti.GetDeclaredMethod(name);
if (mi != null && mi.IsStatic && mi.GetParameters().Length == 0 && mi.ReturnType == typeof(bool))
return () => (bool)mi.Invoke(null, null);
PropertyInfo pi = ti.GetDeclaredProperty(name);
if (pi != null && pi.PropertyType == typeof(bool) && pi.GetMethod != null && pi.GetMethod.IsStatic && pi.GetMethod.GetParameters().Length == 0)
return () => (bool)pi.GetValue(null);
FieldInfo fi = ti.GetDeclaredField(name);
if (fi != null && fi.FieldType == typeof(bool) && fi.IsStatic)
return () => (bool)fi.GetValue(null);
return LookupConditionalMember(ti.BaseType, name);
}

It doesn't flow through because xUnit abstracts away reflection.

The capture is unnecessarily broad and causes spurious warnings in dotnet/runtime repo.

Cc @dotnet/illink

Copy link
Copy Markdown
Member

@sbomer sbomer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks!

@MichalStrehovsky MichalStrehovsky merged commit f61c7ef into main Apr 24, 2026
9 checks passed
@MichalStrehovsky MichalStrehovsky deleted the MichalStrehovsky-patch-1 branch April 24, 2026 01:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants