I have written some code to look at properties using reflection. I have retrieved a list of properties from the class using reflection.
However I need to find out if the property is public or protected. eg:
public string Name{get;set;}
protected int Age{get;set;}
The PropertyInfo class does not seem to expose this information about the property. Is there another way to do this?
Since properties are just syntactic sugar over a pair of
get/setmethods, there’s no such thing as “accessibility” of a property reflection-wise. Rather, you’ll have to find out accessibility levels ofgetandsetmethods separately. To that end, retrieve appropriateMethodInfoobjects withGetGetMethodandGetSetMethodmethods, and from there are variousIsPrivate,IsPublicand other methods and properties.