Scotty-Hudson / fast-member

Automatically exported from code.google.com/p/fast-member
0 stars 0 forks source link

private fields not working #9

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
    public class Foo
    {
        public string _str;

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

Original issue reported on code.google.com by brokenpi...@gmail.com on 22 Nov 2012 at 2:15

GoogleCodeExporter commented 9 years ago
    public class Foo
    {
        private string _str; // -)

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

Original comment by brokenpi...@gmail.com on 22 Nov 2012 at 2:16

GoogleCodeExporter commented 9 years ago
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 ghes...@chaosink.co.uk on 10 Jan 2014 at 11:04

Attachments:

GoogleCodeExporter commented 9 years ago
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 stefanlu...@gmail.com on 6 Feb 2015 at 3:50

GoogleCodeExporter commented 9 years ago
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 stefanlu...@gmail.com on 6 Feb 2015 at 5:08