mirror of
https://gitee.com/ant-design-blazor/ant-design-blazor.git
synced 2024-12-15 09:21:24 +08:00
25 lines
1015 B
C#
25 lines
1015 B
C#
|
using System;
|
|||
|
using System.Collections.Concurrent;
|
|||
|
using System.Reflection;
|
|||
|
using Microsoft.AspNetCore.Components.Forms;
|
|||
|
|
|||
|
namespace AntDesign.Internal
|
|||
|
{
|
|||
|
internal static class DataAnnotationsExtensions
|
|||
|
{
|
|||
|
private static readonly ConcurrentDictionary<(Type ModelType, string FieldName), PropertyInfo> _propertyInfoCache = new ConcurrentDictionary<(Type, string), PropertyInfo>();
|
|||
|
|
|||
|
internal static bool TryGetValidateProperty(this FieldIdentifier fieldIdentifier, out PropertyInfo propertyInfo)
|
|||
|
{
|
|||
|
var cacheKey = (ModelType: fieldIdentifier.Model.GetType(), fieldIdentifier.FieldName);
|
|||
|
propertyInfo = _propertyInfoCache.GetOrAdd(cacheKey, key => cacheKey.ModelType.GetProperty(cacheKey.FieldName));
|
|||
|
return propertyInfo != null;
|
|||
|
}
|
|||
|
|
|||
|
internal static PropertyInfo GetProperty(this FieldIdentifier fieldIdentifier)
|
|||
|
{
|
|||
|
return fieldIdentifier.TryGetValidateProperty(out var property) ? property : null;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|