Skip to content

Possible wrong properties are returned by reflection in ReflectionExtensions.cs #2465

Description

@mikkelbu

When debugging #2448 I noticed that the filtering of properties in ApplyBindingFlags has the same problem as filtering of methods in #2448. The documentation says
https://msdn.microsoft.com/en-us/library/kyaxdd3x(v=vs.110).aspx#Remarks

Specify BindingFlags.NonPublic to include non-public properties (that is, private, internal, and protected properties) in the search. Only protected and internal properties on base classes are returned; private properties on base classes are not returned.

But the code only returns private properties for BindingFlags.NonPublic

if (pub && !priv)
infos = infos.Where(p => (p.GetMethod != null && p.GetMethod.IsPublic) || (p.SetMethod != null && p.SetMethod.IsPublic));
if (priv && !pub)
infos = infos.Where(p => (p.GetMethod == null || p.GetMethod.IsPrivate) && (p.SetMethod == null || p.SetMethod.IsPrivate));

The solution to this can probably be done similar to #2448 (replacing p.GetMethod.IsPrivate with !p.GetMethod.IsPublic), so the main issue is to write some tests that capture the intended behaviour.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions