mercredi 7 janvier 2015

Get all properties which implements a specific generic base type

I have a object which have generic collection properties of diffrent types like this.:



ObservableCollection<T>, BindingList<T>


Now i want to return all properties with implements ICollection<>


I tried this with no success, it seems this reflection query doesnt check the implemented interfaces



IEnumerable<PropertyInfo> childCollections = typeof(T).GetProperties(BindingFlags.Public | BindingFlags.Instance)
.Where(p => p.PropertyType.IsGenericType && p.PropertyType.GetGenericTypeDefinition() == typeof(ICollection<>))
.Select(g => g);





Aucun commentaire:

Enregistrer un commentaire