Skip to content

Commit 6f8d8aa

Browse files
authored
feat(TcpSocket): add data type check prevent assign exception (#548)
* test: 消除提示信息 * refactor: 使用扩展方法重构代码 * refactor: 增加赋值逻辑判断 * test: 更新单元测试 * chore: bump version 9.0.3 * chore: bump version 9.0.2 * refactor: 更正单词拼写错误 * refactor: 优化检查逻辑 * refactor: 更改绑定配置 * chore: 更新 Header 注释
1 parent 6c2054e commit 6f8d8aa

38 files changed

Lines changed: 142 additions & 47 deletions

src/extensions/BootstrapBlazor.Socket/BootstrapBlazor.Socket.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<Version>9.0.2</Version>
4+
<Version>9.0.3</Version>
55
</PropertyGroup>
66

77
<PropertyGroup>

src/extensions/BootstrapBlazor.Socket/DataAdapter/IDataPackageAdapter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) Argo Zhang (argo@163.com). All rights reserved.
1+
// Copyright (c) BootstrapBlazor & Argo Zhang (argo@live.ca). All rights reserved.
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33
// Website: https://www.blazor.zone or https://argozhang.github.io/
44

src/extensions/BootstrapBlazor.Socket/DataConverter/DataConverter.cs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) Argo Zhang (argo@163.com). All rights reserved.
1+
// Copyright (c) BootstrapBlazor & Argo Zhang (argo@live.ca). All rights reserved.
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33
// Website: https://www.blazor.zone or https://argozhang.github.io/
44

@@ -59,9 +59,14 @@ protected virtual bool Parse(ReadOnlyMemory<byte> data, TEntity entity)
5959
{
6060
var attr = p.GetCustomAttribute<DataPropertyConverterAttribute>(false)
6161
?? GetPropertyConverterAttribute(p);
62-
if (attr != null)
62+
if (attr is { Type: not null })
6363
{
64-
p.SetValue(entity, attr.ConvertTo(data));
64+
var value = attr.ConvertTo(data);
65+
var valueType = value?.GetType();
66+
if (valueType != null && p.PropertyType.IsAssignableFrom(valueType))
67+
{
68+
p.SetValue(entity, value);
69+
}
6570
}
6671
}
6772
ret = true;

src/extensions/BootstrapBlazor.Socket/DataConverter/DataConverterCollections.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) Argo Zhang (argo@163.com). All rights reserved.
1+
// Copyright (c) BootstrapBlazor & Argo Zhang (argo@live.ca). All rights reserved.
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33
// Website: https://www.blazor.zone or https://argozhang.github.io/
44

src/extensions/BootstrapBlazor.Socket/DataConverter/DataPropertyConverterAttribute.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) Argo Zhang (argo@163.com). All rights reserved.
1+
// Copyright (c) BootstrapBlazor & Argo Zhang (argo@live.ca). All rights reserved.
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33
// Website: https://www.blazor.zone or https://argozhang.github.io/
44

src/extensions/BootstrapBlazor.Socket/DataConverter/DataTypeConverterAttribute.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) Argo Zhang (argo@163.com). All rights reserved.
1+
// Copyright (c) BootstrapBlazor & Argo Zhang (argo@live.ca). All rights reserved.
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33
// Website: https://www.blazor.zone or https://argozhang.github.io/
44

src/extensions/BootstrapBlazor.Socket/DataConverter/IDataConverter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) Argo Zhang (argo@163.com). All rights reserved.
1+
// Copyright (c) BootstrapBlazor & Argo Zhang (argo@live.ca). All rights reserved.
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33
// Website: https://www.blazor.zone or https://argozhang.github.io/
44

src/extensions/BootstrapBlazor.Socket/DataHandler/DataPackageHandlerBase.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) Argo Zhang (argo@163.com). All rights reserved.
1+
// Copyright (c) BootstrapBlazor & Argo Zhang (argo@live.ca). All rights reserved.
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33
// Website: https://www.blazor.zone or https://argozhang.github.io/
44

src/extensions/BootstrapBlazor.Socket/DataHandler/DelimiterDataPackageHandler.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) Argo Zhang (argo@163.com). All rights reserved.
1+
// Copyright (c) BootstrapBlazor & Argo Zhang (argo@live.ca). All rights reserved.
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33
// Website: https://www.blazor.zone or https://argozhang.github.io/
44

src/extensions/BootstrapBlazor.Socket/DataHandler/FixLengthDataPackageHandler.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) Argo Zhang (argo@163.com). All rights reserved.
1+
// Copyright (c) BootstrapBlazor & Argo Zhang (argo@live.ca). All rights reserved.
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33
// Website: https://www.blazor.zone or https://argozhang.github.io/
44

0 commit comments

Comments
 (0)