mercredi 5 octobre 2016

Check using refelction if property is IEnumerable only of reference types but no string, int, double, etc

Hello I need to check using reflection whether property is IEnumerable type but no IEnumerable of string, int, double, etc.

Right now I have that part of code:

private bool IsEnumerable(PropertyInfo propertyInfo)
{
    return propertyInfo.PropertyType.GetInterfaces().Contains(typeof(IEnumerable)) &&
           propertyInfo.PropertyType != typeof(string);
}

If property is IEnumerable<MyCustomType> this is ok, but if it is IEnumerable<string> my method should return false.





Aucun commentaire:

Enregistrer un commentaire