我想遍历一个类型的所有属性,并想检查一个属性类型是否不是字符串,我该怎么做?
我的类(class)是:
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))
}
但是这段代码不起作用,知道该怎么做吗?
最佳答案
if (property.PropertyType == typeof(string))
关于c# - C#中如何判断类型是否为字符串?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9517333/