|
10 | 10 | namespace BootstrapBlazor.Components; |
11 | 11 |
|
12 | 12 | /// <summary> |
13 | | -/// |
| 13 | +/// 数据转换器集合类 |
14 | 14 | /// </summary> |
15 | | -public class SocketDataConverterCollections |
| 15 | +public sealed class SocketDataConverterCollections |
16 | 16 | { |
17 | 17 | readonly ConcurrentDictionary<Type, ISocketDataConverter> _converters = new(); |
18 | 18 | readonly ConcurrentDictionary<MemberInfo, SocketDataPropertyConverterAttribute> _propertyConverters = new(); |
19 | 19 |
|
20 | 20 | /// <summary> |
21 | | - /// 增加数据类型转换器方法 |
| 21 | + /// 增加指定 <see cref="ISocketDataConverter{TEntity}"/> 数据类型转换器方法 |
22 | 22 | /// </summary> |
23 | 23 | /// <typeparam name="TEntity"></typeparam> |
24 | 24 | /// <param name="converter"></param> |
25 | | - public void AddOrUpdateTypeConverter<TEntity>(ISocketDataConverter<TEntity> converter) |
| 25 | + public void AddTypeConverter<TEntity>(ISocketDataConverter<TEntity> converter) |
26 | 26 | { |
27 | 27 | var type = typeof(TEntity); |
28 | 28 | _converters.AddOrUpdate(type, t => converter, (t, v) => converter); |
29 | 29 | } |
30 | 30 |
|
| 31 | + /// <summary> |
| 32 | + /// 增加默认数据类型转换器方法 转换器使用 <see cref="SocketDataConverter{TEntity}"/> |
| 33 | + /// </summary> |
| 34 | + /// <typeparam name="TEntity"></typeparam> |
| 35 | + public void AddTypeConverter<TEntity>() => AddTypeConverter(new SocketDataConverter<TEntity>(this)); |
| 36 | + |
31 | 37 | /// <summary> |
32 | 38 | /// 添加属性类型转化器方法 |
33 | 39 | /// </summary> |
34 | 40 | /// <typeparam name="TEntity"></typeparam> |
35 | 41 | /// <param name="propertyExpression"></param> |
36 | 42 | /// <param name="attribute"></param> |
37 | | - public void AddOrUpdatePropertyConverter<TEntity>(Expression<Func<TEntity, object?>> propertyExpression, SocketDataPropertyConverterAttribute attribute) |
| 43 | + public void AddPropertyConverter<TEntity>(Expression<Func<TEntity, object?>> propertyExpression, SocketDataPropertyConverterAttribute attribute) |
38 | 44 | { |
39 | 45 | if (propertyExpression.Body is MemberExpression memberExpression) |
40 | 46 | { |
41 | | - if(attribute.Type == null) |
| 47 | + if (attribute.Type == null) |
42 | 48 | { |
43 | 49 | attribute.Type = memberExpression.Type; |
44 | 50 | } |
|
0 commit comments