0
class Abc {
    public Mycollection<Person> Persons { get;set; }
}

class MyCollection<T> : ICollect<T> { ... }

I'm using reflection, getting the PropertyInfo of ABC.Persons.

I want to know if the PropertyInfo is of ICollect<> type - how do I do that?

BrijenVed
  • 43
  • 1
  • 5

1 Answers1

1

This seems similar to: How To Detect If Type is Another Generic Type

public static bool IsAssignableToGenericType(Type givenType, Type genericType) {
var interfaceTypes = givenType.GetInterfaces();

foreach (var it in interfaceTypes)
    if (it.IsGenericType)
        if (it.GetGenericTypeDefinition() == genericType) return true;

Type baseType = givenType.BaseType;
if (baseType == null) return false;

return baseType.IsGenericType &&
    baseType.GetGenericTypeDefinition() == genericType ||
    IsAssignableToGenericType(baseType, genericType);

}

Community
  • 1
  • 1
Denny Ferrassoli
  • 1,763
  • 3
  • 21
  • 40