ant-design-blazor/components/core/DataAnnotationsExtensions.cs
Alsein 82ef62b7a7 feat: add simple table component (#86)
* 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>
2020-05-30 01:46:41 +08:00

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;
}
}
}