1

I have an enum and values ​​in it. I want to get list of these values ​​with get method. I just started and I don't know how to do it.

public enum NotificationTemplateType
{
    [Description("Şablonsuz")] NotTemplate = 0,

    // User Şablonları - 100
    [Description("Yeni Kullanıcı Şablonu")] NewUser = 100,
    [Description("Şifremi Unuttum Şablonu")] ForgotPassword = 101,

    // Seller Şablonları - 200 
    [Description("Yeni Satıcı Şablonu")] NewSeller = 200,
}

[HttpGet("GetType")]
    public List<IActionResult> GetType(NotificationTemplateType notificationTemplateType)
    {
        return Ok(notificationTemplateType.GetAttributeOfType<DescriptionAttribute>()?.Description);
    }
1

1 Answer 1

1

You can get all the values of an enum via GetValues:

Enum.GetValues(typeof(NotificationTemplateType))

Since this returns an array and you want a list, you can just call the ToList method:

Enum.GetValues(typeof(NotificationTemplateType)).ToList()
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.