We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 6070a58 commit accb812Copy full SHA for accb812
src/BootstrapBlazor.Server/Components/Samples/Sockets/DataEntities.razor
@@ -82,6 +82,17 @@ class MockEntity
82
{
83
return new Foo() { Id = data.Span[0], Name = name };
84
}
85
+}</Pre>
86
+ <p>此处返回值会与参数 <code>Type = typeof(Foo)</code> 做数据合规检查,如果返回值无法转换为指定 <code>Type</code> 时不进行赋值操作,代码逻辑如下</p>
87
+ <Pre>var attr = p.GetCustomAttribute<DataPropertyConverterAttribute>(false) ?? GetPropertyConverterAttribute(p);
88
+if (attr is { Type: not null })
89
+{
90
+ var value = attr.ConvertTo(data);
91
+ var valueType = value?.GetType();
92
+ if (valueType != null && p.PropertyType.IsAssignableFrom(valueType))
93
+ {
94
+ p.SetValue(entity, value);
95
+ }
96
}</Pre>
97
<p>更多技术细节可以参考以上内置提供的转换器源码</p>
98
</DemoBlock>
0 commit comments