Only enum DisplayAttribute Description? Why not all the properties, like Name? #1718

Closed
opened 2026-01-29 17:57:41 +00:00 by claunia · 2 comments
Owner

Originally created by @JJong-nl on GitHub (Apr 17, 2025).

why only the enum description?
dd02bf8b8d/Radzen.Blazor/Extensions.cs (L18-L31)

Please add the folowing code for all the properties of the DisplayAttribute like the Name propertie

    public static string GetDisplay<TKey>(this Enum enumValue, Func<System.ComponentModel.DataAnnotations.DisplayAttribute, TKey> keySelector, Func<string, string> translationFunction = null)
    {
        var enumValueAsString = enumValue.ToString();
        var val = enumValue.GetType().GetMember(enumValueAsString).FirstOrDefault();
        var attribute = val?.GetCustomAttribute<System.ComponentModel.DataAnnotations.DisplayAttribute>();

        var enumVal = attribute != null ? keySelector(attribute)?.ToString() ?? enumValueAsString : enumValueAsString;

        if (translationFunction != null)
            return translationFunction(enumVal);

        return enumVal;
    }

now we can do something line myEnum.GetDisplay(a=>a.Name)

Originally created by @JJong-nl on GitHub (Apr 17, 2025). why only the enum description? https://github.com/radzenhq/radzen-blazor/blob/dd02bf8b8dff5e003fe6b4ee28ab09be28d874f3/Radzen.Blazor/Extensions.cs#L18-L31 Please add the folowing code for all the properties of the DisplayAttribute like the `Name` propertie ``` public static string GetDisplay<TKey>(this Enum enumValue, Func<System.ComponentModel.DataAnnotations.DisplayAttribute, TKey> keySelector, Func<string, string> translationFunction = null) { var enumValueAsString = enumValue.ToString(); var val = enumValue.GetType().GetMember(enumValueAsString).FirstOrDefault(); var attribute = val?.GetCustomAttribute<System.ComponentModel.DataAnnotations.DisplayAttribute>(); var enumVal = attribute != null ? keySelector(attribute)?.ToString() ?? enumValueAsString : enumValueAsString; if (translationFunction != null) return translationFunction(enumVal); return enumVal; } ``` now we can do something line `myEnum.GetDisplay(a=>a.Name)`
Author
Owner

@akorchev commented on GitHub (Apr 19, 2025):

Hi @JJong-nl,

We are not sure what you are asking. Please elaborate.

@akorchev commented on GitHub (Apr 19, 2025): Hi @JJong-nl, We are not sure what you are asking. Please elaborate.
Author
Owner

@enchev commented on GitHub (May 7, 2025):

I'm closing this since there is no additional information.

@enchev commented on GitHub (May 7, 2025): I'm closing this since there is no additional information.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/radzen-blazor#1718