Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

the best way to make a collection of types and check against it

how can i make a collection that can store a data type (say string, datetime, decimal, etc..)? and that use this collection to perform comparison as such:

if (pi.PropertyType.IsIn ([how can check against the collection of type) //where pi is a property info]))
{

}

any suggestions?

like image 274
user384080 Avatar asked Dec 05 '25 02:12

user384080


1 Answers

List<Type> types = new List<Type> {typeof(string), typeof(int)};
if (types.Contains(pi.PropertyType))
{
  //do stuff
}
like image 134
Hari Avatar answered Dec 06 '25 16:12

Hari