EnumExtensions Methods
GetDisplayName 
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"Syntax:
public static string GetDisplayName(
	this Enum value
)Parameters:
Parameter
Description
value
Type: Enum The enum value on which the extension is called and for which the display name will be returned.
Return Value:
The display name string associated with the enum value. If the value has no Description attribute, null is returned.
GetFlags 
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
   }Syntax:
public static IEnumerable<Enum> GetFlags(
	this Enum input
)Parameters:
Parameter
Description
input
Type: Enum The enum value on which the extension is called and for which the flags will be returned.
Return Value:
An IEnumerable<Enum> which enumerates all flags that are set in the input value.
Last updated
Was this helpful?
