public class Foo
{
public string _str;
public Foo(string str)
{
_str = str;
}
}
Comment #1
Posted on Nov 22, 2012 by Happy Oxpublic class Foo
{
private string _str; // -)
public Foo(string str)
{
_str = str;
}
}
Comment #2
Posted on Jan 10, 2014 by Massive CamelI'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.
- PrivateAccess.patch 4.82KB
Comment #3
Posted on Feb 6, 2015 by Grumpy BearI 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 BearOh well, that didn't work either. Apparantly you can't access private fields, you'll get an exception if you try. See here:
Status: New
Labels:
Type-Defect
Priority-Medium