EnumExtensions Methods
Returns the display name of an Enum from the Description attribute in the enum. E.g:
public enum PlanStatus {
[Description("Plan In Review")]
InReview = 20
}
PlanStatus.InReview.GetDisplayName(); // -> "Plan In Review"
public static string GetDisplayName(
this Enum value
)
Parameter | Description |
value | Type: Enum
The enum value on which the extension is called and for which the display name will be returned. |
The display name string associated with the enum value. If the value has no Description attribute, null is returned.
Returns all flags that are set for a flagged enum value. E.g:
[Flags]
public Permissions
{
Login = 1,
Read = 2,
Write = 4,
Execute = 8
}
var userPermissions = Permissions.Login | Permissions.Read | Permissions.Write;
foreach (Permissions permission in userPermissions.GetFlags())
{
// do something with the individual permission
}
public static IEnumerable<Enum> GetFlags(
this Enum input
)
Parameter | Description |
input | Type: Enum
The enum value on which the extension is called and for which the flags will be returned. |
Last modified 3yr ago