Skip to content

Commit e849181

Browse files
committed
refactor: 优化检查逻辑
1 parent e39104d commit e849181

1 file changed

Lines changed: 6 additions & 5 deletions

File tree

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

Lines changed: 6 additions & 5 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,12 +59,13 @@ 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-
var v = attr.ConvertTo(data);
65-
if (v?.GetType() == attr.Type)
64+
var value = attr.ConvertTo(data);
65+
var valueType = value?.GetType();
66+
if (valueType != null && p.PropertyType.IsAssignableFrom(valueType))
6667
{
67-
p.SetValue(entity, v);
68+
p.SetValue(entity, value);
6869
}
6970
}
7071
}

0 commit comments

Comments
 (0)