I am looping through a list of objects. Each object can contain one or more properties. I want to see if the property is either: a string, a numerical value, a boolean, or a Date time.
I did some research and found out to get the property type you can use:
object prop in item.GetType().GetProperties();
So I updated my looping to:
foreach (var item in myGenericList)
{
foreach (object prop in item.GetType().GetProperties())
{
//Combobox
if (prop.Equals(typeof(string)))
{
GenerateComboBox(prop);
}
else if (prop is decimal || prop is int || prop is double)
{
GenerateRangeControl(prop);
}
else if (prop is bool)
{
GenerateToggle(prop);
}
else if (prop is DateTime)
{
GenerateDatePicker(prop);
}
}
}
But none of the conditions are being met. (No if-condition is true) How can I loop through a generic list of objects and find the data type of each property inside the object?