In previous articles Get enumeration items as a list in C# and Populate dropdown with enumeration items in ASP.NET Core we that saw how to get enumeration items as a collection to bind it to data controls like dropdown etc.
In this article we will see that how can we get the description given as an attribute with an item. We may need this information on various places, say we have listing of users and we need to show each user’s status but in a descriptive way.
Here is our example enumeration:
enum UserStatus
{
[Description("Pending Verification")]
PendingVerification = 1,
[Description("Pending Admin Approval")]
PendingAdminApproval = 2,
[Description("Active")]
...