我想通过反射来了解有关字段类型的详细信息。
我知道我可以发现它是Type.IsValueType
的值类型。但是从那里我怎么知道它是一个数字?定点数?已签名还是未签名?
是否有类似Type.IsSigned
的东西?
答案 0 :(得分:6)
没有很多无符号数字类型,所以为什么不组成一个数字列表呢?
if (new Type[] { typeof(ushort), typeof(uint), typeof(ulong), typeof(byte) }.Contains(type))
{
// unsigned.
}
或者如果您只想比较值(此处为o
):
if (o is ushort || o is uint || o is ulong || o is byte)
{
// unsigned.
}