Reputation: 36048
I know how to get an object properties using reflection:
var properties = typeof(T).GetProperties();
now how do I know if properties[0] is a string? or maybe it is a int? how can I know?
Upvotes: 3
Views: 126
Reputation: 1500525
Each element of properties
will be a PropertyInfo
, which has a PropertyType
property, indicating the type of the property.
So for example, you might use:
if (properties[0].PropertyType == typeof(string))
or if you wanted to check something in an inheritance-permitting way:
if (typeof(Stream).IsAssignableFrom(properties[0].PropertyType))
Upvotes: 10