Using GetProperties() with BindingFlags.DeclaredOnly in .NET Reflection
.net, c#, reflection
Solution
If you specify any `BindingFlags`, then you need to specify explicitly what properties you want to get. For example:
sometype.GetProperties (BindingFlags.DeclaredOnly |
BindingFlags.Public |
BindingFlags.Instance);
Problem
If I use ``` sometype.GetProperties(); ``` I get all of the properties from the type and it's parent. However I only want to retrieve the properties defined explicitly in this type (not the parents). I thought that was what the `BindingFlags.DeclaredOnly` option was for. However, when I try this: ``` sometype.GetProperties(BindingFlags.DeclaredOnly); ``` I get 0 properties. Anyone know what I am doing wrong?