如何检查值是Enum数组类型? c#

问题描述 投票:0回答:1

枚举类型可以检查为

obj.PropertyType.IsEnum == true

那么我如何检查值是枚举数组类型?

// obj = SomeEnum[20]

else if (obj.PropertyType == typeof(Enum[])) // It doesn't work as I think
{
    SetValue(parser, obj);
}
c# typechecking
1个回答
0
投票
var objType = obj.GetType();

if (...)
{
    ...
}
else if (objType.IsArray && objType.GetElementType().IsEnum)
{
    ...
}
© www.soinside.com 2019 - 2024. All rights reserved.