If you only want properties that are defined by the class but not inherited, you can pass the BindingFlags.DeclaredOnly binding BindingFlags.DeclaredOnly to the GetProperties method.
Ref: https://msdn.microsoft.com/en-us/library/system.reflection.bindingflags(v=vs.110).aspx
Change 1:
Thanks to Rene for pointing out that this is not a working answer yet.
In fact, I often forget to pass these required bind flags to GetXXX methods.
And the program will always work as expected ...
In any case, in order to make this method work, you must always specify 1) the visibility / accessibility (i.e., public or not) and 2) the area (static / instance) of the required members.
If you do not, the GetXXX return value will be empty (or an empty array, I'm not quite sure about this, but you will get an idea.)
In conclusion, so that everything is correct, you could:
1. Select BindingFlags.Public or BindingFlags.NonPublic or both.
2. Select BindingFlags.Instance or BidningFlags.Static or both.
3. Combine the selected flags with the previous steps using BindingFlags.DeclaredOnly
So, in your case, the result will be the string specified in the Rene answer.
(I need to edit the answer, because it seems that I still can not comment ...)
Yac
source share