2

I can check for a single type by using

if (e.PropertyType == typeof(EntityCollection<Search_SearchCodes>))

But but I really want to avoid all objects that are EntityCollections

if (e.PropertyType == typeof(EntityCollection))

Is there a way to do this?

cost
  • 4,420
  • 8
  • 48
  • 80

1 Answers1

8

You can do this by confirming that the type is a generic type, and its generic type definition is equal to the EntityCollection<> open generic type.

var type = e.PropertyType;
var isEntityCollection = type.IsGenericType && 
    type.GetGenericTypeDefinition() == typeof(EntityCollection<>);
Community
  • 1
  • 1
Jon
  • 428,835
  • 81
  • 738
  • 806
  • Excellent, that works great. Also, it never occurred to me that you can use multiple conditionals when assigning a boolean, so I learned two cool things, thanks! – cost Sep 13 '13 at 20:14