mirror of
https://github.com/aaru-dps/Aaru.Server.git
synced 2025-12-16 19:24:27 +00:00
20 lines
623 B
C#
20 lines
623 B
C#
using System.ComponentModel;
|
|
using System.Reflection;
|
|
|
|
namespace Aaru.Server;
|
|
|
|
public static class DisplayNameHelper
|
|
{
|
|
public static string GetDisplayName(Type type, string propertyName)
|
|
{
|
|
PropertyInfo? prop = type.GetProperty(propertyName);
|
|
|
|
if(prop is null) return propertyName;
|
|
|
|
DisplayNameAttribute? displayAttr = prop.GetCustomAttributes(typeof(DisplayNameAttribute), true)
|
|
.OfType<DisplayNameAttribute>()
|
|
.FirstOrDefault();
|
|
|
|
return displayAttr?.DisplayName ?? propertyName;
|
|
}
|
|
} |