reflection - Know the types of properties in an object c# -
i know how object properties using reflection:
var properties = typeof(t).getproperties();
now how know if properties[0] string? or maybe int? how can know?
each element of properties
propertyinfo
, has propertytype
property, indicating type of property.
so example, might use:
if (properties[0].propertytype == typeof(string))
or if wanted check in inheritance-permitting way:
if (typeof(stream).isassignablefrom(properties[0].propertytype))
Comments
Post a Comment