Api/Brizco.Common/Extensions/PropertyExtensions.cs

17 lines
501 B
C#
Raw Normal View History

2023-09-08 12:25:21 +03:30
using System.ComponentModel.DataAnnotations;
using System.Reflection;
namespace Brizco.Common.Extensions
{
public static class PropertyExtensions
{
public static string GetPropertyDisplayName(this MemberInfo propertyExpression)
{
var memberInfo = propertyExpression;
var attr = memberInfo.GetCustomAttributes<DisplayAttribute>().FirstOrDefault();
if (attr == null) return memberInfo.Name;
return attr.Name;
}
}
}