I know how to get an object properties using reflection:
var properties = typeof(T).GetProper开发者_如何学运维ties();
now how do I know if properties[0] is a string? or maybe it is a int? how can I know?
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))
精彩评论