Skip to content

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

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

Closed
mikkelbu opened this issue Oct 1, 2017 · 0 comments
Assignees
Milestone

Comments

@mikkelbu
Copy link
Member

mikkelbu commented Oct 1, 2017

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.

@mikkelbu mikkelbu self-assigned this Oct 1, 2017
@mikkelbu mikkelbu added the is:bug label Oct 1, 2017
mikkelbu added a commit that referenced this issue Oct 3, 2017
As the documentation states "Specify BindingFlags.NonPublic
to include non-public properties (that is, private, internal,
and protected properties) in the search.

Fixes #2465
@rprouse rprouse added this to the 3.9 milestone Nov 3, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants