我想通过反射了解有关字段类型的详细信息.
我知道我可以发现它是一个值类型Type.IsValueType
.但是从那里我怎么知道它是一个数字?固定点数?有签名还是未签名?
有什么相似的Type.IsSigned
吗?
没有那么多未签名的数字类型,所以为什么不组成一个列表:
if (new Type[] { typeof(ushort), typeof(uint), typeof(ulong), typeof(byte) }.Contains(type))
{
// unsigned.
}
Run Code Online (Sandbox Code Playgroud)
或者,如果您只想比较值(此处o
):
if (o is ushort || o is uint || o is ulong || o is byte)
{
// unsigned.
}
Run Code Online (Sandbox Code Playgroud)