Determine if a property is a kind of array by reflection

后端 未结 5 618
悲&欢浪女
悲&欢浪女 2020-12-24 01:46

How can I determine if a property is a kind of array.

Example:

public bool IsPropertyAnArray(PropertyInfo property)
{
    // return true if type is I         


        
5条回答
  •  醉话见心
    2020-12-24 02:09

    Excluding String class as it qualifies as a collection because it implements IEnumerable.

    public bool IsPropertyACollection(this PropertyInfo property)
    {
        return (!typeof(String).Equals(property.PropertyType) && 
            typeof(IEnumerable).IsAssignableFrom(property.PropertyType));
    }
    

提交回复
热议问题