我想通过一个类型的所有属性,并希望检查一个属性类型是不是一个字符串,我该怎么做?如何检查一个类型是否是C#中的字符串?
我的班级:
public class MarkerInfo
{
public string Name { get; set; }
public byte[] Color { get; set; }
public TypeId Type { get; set; }
public bool IsGUIVisible { get; set; }
public MarkerInfo()
{
Color = new byte[4]; // A, R, G, B
IsGUIVisible = true;
}
}
和我使用的检查类型的代码是:
foreach (var property in typeof(MarkerInfo).GetProperties())
{
if (property.PropertyType is typeof(string))
}
但这种代码是不工作,任何想法如何做到这一点?