Skip to content

Commit e822300

Browse files
committed
refactor: 精简方法名称
1 parent afa0665 commit e822300

File tree

3 files changed

+13
-13
lines changed

3 files changed

+13
-13
lines changed

src/BootstrapBlazor/Services/TcpSocket/DataConverter/SocketDataConverterCollections.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
namespace BootstrapBlazor.Components;
1111

1212
/// <summary>
13-
///
13+
/// 数据转换器集合类
1414
/// </summary>
15-
public class SocketDataConverterCollections
15+
public sealed class SocketDataConverterCollections
1616
{
1717
readonly ConcurrentDictionary<Type, ISocketDataConverter> _converters = new();
1818
readonly ConcurrentDictionary<MemberInfo, SocketDataPropertyConverterAttribute> _propertyConverters = new();
@@ -22,7 +22,7 @@ public class SocketDataConverterCollections
2222
/// </summary>
2323
/// <typeparam name="TEntity"></typeparam>
2424
/// <param name="converter"></param>
25-
public void AddOrUpdateTypeConverter<TEntity>(ISocketDataConverter<TEntity> converter)
25+
public void AddTypeConverter<TEntity>(ISocketDataConverter<TEntity> converter)
2626
{
2727
var type = typeof(TEntity);
2828
_converters.AddOrUpdate(type, t => converter, (t, v) => converter);
@@ -32,15 +32,15 @@ public void AddOrUpdateTypeConverter<TEntity>(ISocketDataConverter<TEntity> conv
3232
/// 增加默认数据类型转换器方法 转换器使用 <see cref="SocketDataConverter{TEntity}"/>
3333
/// </summary>
3434
/// <typeparam name="TEntity"></typeparam>
35-
public void AddOrUpdateTypeConverter<TEntity>() => AddOrUpdateTypeConverter(new SocketDataConverter<TEntity>(this));
35+
public void AddTypeConverter<TEntity>() => AddTypeConverter(new SocketDataConverter<TEntity>(this));
3636

3737
/// <summary>
3838
/// 添加属性类型转化器方法
3939
/// </summary>
4040
/// <typeparam name="TEntity"></typeparam>
4141
/// <param name="propertyExpression"></param>
4242
/// <param name="attribute"></param>
43-
public void AddOrUpdatePropertyConverter<TEntity>(Expression<Func<TEntity, object?>> propertyExpression, SocketDataPropertyConverterAttribute attribute)
43+
public void AddPropertyConverter<TEntity>(Expression<Func<TEntity, object?>> propertyExpression, SocketDataPropertyConverterAttribute attribute)
4444
{
4545
if (propertyExpression.Body is MemberExpression memberExpression)
4646
{

test/UnitTest/Services/SocketDataConverterCollectionsTest.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,21 @@ protected override void ConfigureConfiguration(IServiceCollection services)
1616

1717
services.ConfigureSocketDataConverters(options =>
1818
{
19-
options.AddOrUpdateTypeConverter(new SocketDataConverter<MockEntity>());
20-
options.AddOrUpdatePropertyConverter<MockEntity>(entity => entity.Header, new SocketDataPropertyConverterAttribute()
19+
options.AddTypeConverter<MockEntity>();
20+
options.AddPropertyConverter<MockEntity>(entity => entity.Header, new SocketDataPropertyConverterAttribute()
2121
{
2222
Offset = 0,
2323
Length = 5
2424
});
25-
options.AddOrUpdatePropertyConverter<MockEntity>(entity => entity.Body, new SocketDataPropertyConverterAttribute()
25+
options.AddPropertyConverter<MockEntity>(entity => entity.Body, new SocketDataPropertyConverterAttribute()
2626
{
2727
Offset = 5,
2828
Length = 2
2929
});
3030

3131
// 为提高代码覆盖率 重复添加转换器以后面的为准
32-
options.AddOrUpdateTypeConverter(new SocketDataConverter<MockEntity>());
33-
options.AddOrUpdatePropertyConverter<MockEntity>(entity => entity.Header, new SocketDataPropertyConverterAttribute()
32+
options.AddTypeConverter<MockEntity>();
33+
options.AddPropertyConverter<MockEntity>(entity => entity.Header, new SocketDataPropertyConverterAttribute()
3434
{
3535
Offset = 0,
3636
Length = 5

test/UnitTest/Services/TcpSocketFactoryTest.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -770,13 +770,13 @@ public async Task TryGetTypeConverter_Ok()
770770
{
771771
builder.ConfigureSocketDataConverters(options =>
772772
{
773-
options.AddOrUpdateTypeConverter<OptionConvertEntity>();
774-
options.AddOrUpdatePropertyConverter<OptionConvertEntity>(entity => entity.Header, new SocketDataPropertyConverterAttribute()
773+
options.AddTypeConverter<OptionConvertEntity>();
774+
options.AddPropertyConverter<OptionConvertEntity>(entity => entity.Header, new SocketDataPropertyConverterAttribute()
775775
{
776776
Offset = 0,
777777
Length = 5
778778
});
779-
options.AddOrUpdatePropertyConverter<OptionConvertEntity>(entity => entity.Body, new SocketDataPropertyConverterAttribute()
779+
options.AddPropertyConverter<OptionConvertEntity>(entity => entity.Body, new SocketDataPropertyConverterAttribute()
780780
{
781781
Offset = 5,
782782
Length = 2

0 commit comments

Comments
 (0)