Type.GetProperties excludes properties using the [] operator

When i call

Type.GetProperties(BindingFlags.Public | BindingFlags.Instance)

I also get properties with [] operators. So, for example, I have:

MyType
-> Property1
-> Property2[string] 

And the returned PropertyInfo list contains both Property1 and Property2.

How can I exclude properties with operators?

I would prefer this to happen via BindingFlags, but iterating over the afterwords from PropertyInfo would be fine, but I can't see anything on the PropertyInfo class that indicates whether this has an operator.

+4
source share
2 answers

, BindingFlags, , PropertyInfo.GetIndexParameters() : , .

+4

LINQ :

Type.GetProperties(BindingFlags.Public | BindingFlags.Instance).Where(prop => prop.GetIndexParameters().Length == 0);
+4

Source: https://habr.com/ru/post/1525689/


All Articles