Is it possible to do it? How?
Thank you for your help!
views:
64answers:
2This will return an empty array, you also need to specify BindingFlags.Instance or BindingFlags.Static.
Thomas Levesque
2010-09-22 08:30:01
+2
A:
Yes, you can. Specify BindingFlags.NonPublic
in your call to GetProperties()
.
class Program
{
static void Main(string[] args)
{
var f = new Foo();
foreach (var fi in f.GetType().GetProperties(
BindingFlags.NonPublic | BindingFlags.Instance))
{
Console.WriteLine(fi);
}
}
}
public class Foo
{
private string Prop { get; set; }
}
Michael Petrotta
2010-09-22 08:23:09