Export to GitHub

fast-member - issue #9

private fields not working


Posted on Nov 22, 2012 by Happy Ox
public class Foo
{
    public string _str;

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

Comment #1

Posted on Nov 22, 2012 by Happy Ox
public class Foo
{
    private string _str; // -)

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

Comment #2

Posted on Jan 10, 2014 by Massive Camel

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.

Attachments

Comment #3

Posted on Feb 6, 2015 by Grumpy Bear

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.

Comment #4

Posted on Feb 6, 2015 by Grumpy Bear

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

Status: New

Labels:
Type-Defect Priority-Medium