Skip to content
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

private fields not working #9

Open
GoogleCodeExporter opened this issue Nov 23, 2015 · 7 comments · May be fixed by #86
Open

private fields not working #9

GoogleCodeExporter opened this issue Nov 23, 2015 · 7 comments · May be fixed by #86

Comments

@GoogleCodeExporter
Copy link

    public class Foo
    {
        public string _str;

        public Foo(string str)
        {
            _str = str;
        }
    }

Original issue reported on code.google.com by [email protected] on 22 Nov 2012 at 2:15

@GoogleCodeExporter
Copy link
Author

    public class Foo
    {
        private string _str; // -)

        public Foo(string str)
        {
            _str = str;
        }
    }

Original comment by [email protected] on 22 Nov 2012 at 2:16

@GoogleCodeExporter
Copy link
Author

I've submitted a patch upstream which allows access to private and protected 
members when you create a type accessor like:

var accessor = TypeAccessor.Create(typeof(yourClass), true);

The patchset is attached to this comment.

Original comment by [email protected] on 10 Jan 2014 at 11:04

Attachments:

@GoogleCodeExporter
Copy link
Author

I applied the patch and I still only get public members returned.

If you look in MemberSet.cs @ 16, it makes sense because type.GetFields() only 
returns public members if there are no arguments.

Adding:
BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance

to the arguments of that method call does seem to work. 

Original comment by [email protected] on 6 Feb 2015 at 3:50

@GoogleCodeExporter
Copy link
Author

Oh well, that didn't work either. Apparantly you can't access private fields, 
you'll get an exception if you try. See here:

http://stackoverflow.com/questions/6356371/help-needed-with-typeaccessexception-
attempt-by-method-to-access-type-f

Original comment by [email protected] on 6 Feb 2015 at 5:08

@frankiDotNet
Copy link

Something new here?
The code seems to be working only for public setters..

@guylando
Copy link

@mgravell is there a workaround to this please?

@erwan-joly
Copy link

Any news on this issue ? Seems to only work for public (tried private/protected/internal/internal protected

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

Successfully merging a pull request may close this issue.

4 participants