mardi 3 juillet 2018

How to know if a property is a type of List

I have this these classes.

public class MyClass:BaseClass
{ }

public class BaseClass
{ }

public class CollectionClass
{
   public string SomeProperty {get; set;}

   public List<MyClass> Collection {get; set;}
}

In my code I want to find out if property in some object (e. g. CollectionClass) is a type of List<BaseClass> also I want to return true if property is a type of List<MyClass>. Code below explains that.

public bool ContainsMyCollection(object obj)
{
   foreach(var property in obj.GetType().GetProperties())
   {
      //  Idk how to accomplish that
      if(property isTypeof List<BaseClass>)
         return true;
   }
   return false
}





Aucun commentaire:

Enregistrer un commentaire