private static InternalPermissionsEnum? GetEnumByStringValueAttribute(string value)
{
Type enumType = typeof(InternalPermissionsEnum);
foreach (Enum val in Enum.GetValues(enumType))
{
FieldInfo fi = enumType.GetField(val.ToString());
StringValueAttribute[] attributes = (StringValueAttribute[])fi.GetCustomAttributes(typeof(StringValueAttribute), false);
if (attributes.Length <= 0) continue;
StringValueAttribute attr = attributes[0];
if (attr.Value == value)
{
return (InternalPermissionsEnum)val;
}
}
return null;
}
{
Type enumType = typeof(InternalPermissionsEnum);
foreach (Enum val in Enum.GetValues(enumType))
{
FieldInfo fi = enumType.GetField(val.ToString());
StringValueAttribute[] attributes = (StringValueAttribute[])fi.GetCustomAttributes(typeof(StringValueAttribute), false);
if (attributes.Length <= 0) continue;
StringValueAttribute attr = attributes[0];
if (attr.Value == value)
{
return (InternalPermissionsEnum)val;
}
}
return null;
}
No comments:
Post a Comment