mirror of
https://gitee.com/ant-design-blazor/ant-design-blazor.git
synced 2024-12-16 01:41:14 +08:00
82ef62b7a7
* fix: add @commitlint/config-conventional to devDependencies * feat: add basic table implementation * feat: continue adding definitions * feat: end of work in 20200414 * fix: add readonly to csssizelength * fix: warnings from table * fix: add ignorecase to csssizelength * feat: refactor table * feat: add simple table Co-authored-by: ElderJames <shunjiey@hotmail.com>
35 lines
1.2 KiB
C#
35 lines
1.2 KiB
C#
using System;
|
|
using System.Collections.Concurrent;
|
|
using System.ComponentModel;
|
|
using AntDesign.Internal;
|
|
using Microsoft.AspNetCore.Components.Forms;
|
|
|
|
namespace AntDesign
|
|
{
|
|
internal static class FieldIdentifierExtensions
|
|
{
|
|
private static readonly ConcurrentDictionary<(Type ModelType, string FieldName), string> _displayNameCache = new ConcurrentDictionary<(Type, string), string>();
|
|
|
|
public static string GetDisplayName(this FieldIdentifier fieldIdentifier)
|
|
{
|
|
var cacheKey = (Type: fieldIdentifier.Model.GetType(), fieldIdentifier.FieldName);
|
|
|
|
var displayName = _displayNameCache.GetOrAdd(cacheKey, key =>
|
|
{
|
|
if (fieldIdentifier.TryGetValidateProperty(out var propertyInfo))
|
|
{
|
|
var displayNameAttribute = propertyInfo.GetCustomAttributes(typeof(DisplayNameAttribute), true);
|
|
if (displayNameAttribute.Length > 0)
|
|
{
|
|
return ((DisplayNameAttribute)displayNameAttribute[0]).DisplayName ?? key.FieldName;
|
|
}
|
|
}
|
|
|
|
return key.FieldName;
|
|
});
|
|
|
|
return displayName;
|
|
}
|
|
}
|
|
}
|