110,536
社区成员
发帖
与我相关
我的任务
分享
public static bool ConvertIntToEnumEnable(Type type, int value)
{
try
{
FieldInfo[] fields = type.GetFields();
if (fields == null || fields.Length == 0)
{
return false;
}
foreach (var field in fields)
{
int enumValue = (int)type.InvokeMember(field.Name, BindingFlags.GetField, null, null, null);
if (value == enumValue)
{
return true;
}
}
return false;
}
catch (Exception ex)
{
return false;
}
}
public static bool ConvertIntToEnumEnable(Type type, int value)
{
foreach (object val in Enum.GetValues(type))
{
if(Convert.ToInt32(val)==value)
return true;
}
return false;
}
public static bool ConvertIntToEnumEnable(Type type, int value)
{
foreach (object val in Enum.GetValues(type))
{
if(Enum.Format(type,val,"d")==value.ToString())
return true;
}
return false;
}