Skip to content

Commit a8b3118

Browse files
authored
feat(IDynamicObject): disable support complex object (#5250)
* refactor: 移除 NET5 框架代码 * refactor: 精简代码 * doc: 更新注释文档 * refactor: 重构代码提供可读性 * doc: 增加注释 * refactor: 重命名测试类 * doc: 增加注释 * feat: 动态不支持复杂类 * feat: Lambda 扩展方法支持参数是否支持复杂类型 * feat: 增加 SupportComplexProperty 参数 * test: 增加单元测试 * chore: bump version 9.3.1-beta03
1 parent 10fe382 commit a8b3118

File tree

12 files changed

+119
-183
lines changed

12 files changed

+119
-183
lines changed

src/BootstrapBlazor/BootstrapBlazor.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.Razor">
22

33
<PropertyGroup>
4-
<Version>9.3.1-beta02</Version>
4+
<Version>9.3.1-beta03</Version>
55
</PropertyGroup>
66

77
<ItemGroup>

src/BootstrapBlazor/Components/EditorForm/EditorItem.cs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,7 @@ namespace BootstrapBlazor.Components;
1212
/// EditorItem 组件
1313
/// </summary>
1414
/// <remarks>用于 EditorForm 的 FieldItems 模板内</remarks>
15-
#if NET6_0_OR_GREATER
1615
public class EditorItem<TModel, TValue> : ComponentBase, IEditorItem
17-
#else
18-
public class EditorItem<TValue> : ComponentBase, IEditorItem
19-
#endif
2016
{
2117
/// <summary>
2218
/// 获得/设置 绑定字段值
@@ -108,9 +104,6 @@ public class EditorItem<TValue> : ComponentBase, IEditorItem
108104
/// 获得/设置 编辑模板
109105
/// </summary>
110106
[Parameter]
111-
#if NET5_0
112-
public RenderFragment<object>? EditTemplate { get; set; }
113-
#elif NET6_0_OR_GREATER
114107
public RenderFragment<TModel>? EditTemplate { get; set; }
115108

116109
RenderFragment<object>? IEditorItem.EditTemplate
@@ -126,7 +119,6 @@ public class EditorItem<TValue> : ComponentBase, IEditorItem
126119
{
127120
}
128121
}
129-
#endif
130122

131123
/// <summary>
132124
/// 获得/设置 组件类型 默认为 null

src/BootstrapBlazor/Components/Table/TableColumn.cs

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -291,27 +291,6 @@ public class TableColumn<TItem, TType> : BootstrapComponentBase, ITableColumn
291291
/// 获得/设置 显示模板
292292
/// </summary>
293293
[Parameter]
294-
#if NET5_0
295-
public RenderFragment<TableColumnContext<object, TType>>? Template { get; set; }
296-
297-
/// <summary>
298-
/// 内部使用负责把 object 类型的绑定数据值转化为泛型数据传递给前端
299-
/// </summary>
300-
RenderFragment<object>? ITableColumn.Template
301-
{
302-
get => Template == null ? null : new RenderFragment<object>(context => builder =>
303-
{
304-
// 此处 context 为行数据
305-
var fieldName = GetFieldName();
306-
var value = Utility.GetPropertyValue<object, TType>(context, fieldName);
307-
builder.AddContent(0, Template.Invoke(new TableColumnContext<object, TType>(context, value)));
308-
});
309-
set
310-
{
311-
312-
}
313-
}
314-
#elif NET6_0_OR_GREATER
315294
public RenderFragment<TableColumnContext<TItem, TType?>>? Template { get; set; }
316295

317296
/// <summary>
@@ -338,15 +317,11 @@ public class TableColumn<TItem, TType> : BootstrapComponentBase, ITableColumn
338317

339318
}
340319
}
341-
#endif
342320

343321
/// <summary>
344322
/// 获得/设置 编辑模板
345323
/// </summary>
346324
[Parameter]
347-
#if NET5_0
348-
public RenderFragment<object>? EditTemplate { get; set; }
349-
#elif NET6_0_OR_GREATER
350325
public RenderFragment<TItem>? EditTemplate { get; set; }
351326

352327
RenderFragment<object>? IEditorItem.EditTemplate
@@ -362,16 +337,12 @@ public class TableColumn<TItem, TType> : BootstrapComponentBase, ITableColumn
362337
{
363338
}
364339
}
365-
#endif
366340

367341
/// <summary>
368342
/// 获得/设置 搜索模板
369343
/// </summary>
370344
/// <value></value>
371345
[Parameter]
372-
#if NET5_0
373-
public RenderFragment<object>? SearchTemplate { get; set; }
374-
#elif NET6_0_OR_GREATER
375346
public RenderFragment<TItem>? SearchTemplate { get; set; }
376347

377348
RenderFragment<object>? ITableColumn.SearchTemplate
@@ -387,7 +358,6 @@ public class TableColumn<TItem, TType> : BootstrapComponentBase, ITableColumn
387358
{
388359
}
389360
}
390-
#endif
391361

392362
/// <summary>
393363
/// 获得/设置 过滤模板

src/BootstrapBlazor/Dynamic/DataTableDynamicContext.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ private List<IDynamicObject> BuildItems()
123123
{
124124
if (!row.IsNull(col))
125125
{
126-
Utility.SetPropertyValue<object, object?>(d, col.ColumnName, row[col]);
126+
Utility.SetPropertyValue<object, object?>(d, col.ColumnName, row[col], false);
127127
}
128128
}
129129

@@ -200,7 +200,7 @@ public override async Task AddAsync(IEnumerable<IDynamicObject> selectedItems)
200200
{
201201
if (col.DefaultValue != DBNull.Value)
202202
{
203-
Utility.SetPropertyValue<object, object?>(dynamicObject, col.ColumnName, col.DefaultValue);
203+
Utility.SetPropertyValue<object, object?>(dynamicObject, col.ColumnName, col.DefaultValue, false);
204204
}
205205
}
206206
dynamicObject.Row = row;

src/BootstrapBlazor/Dynamic/DataTableDynamicObject.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public class DataTableDynamicObject : DynamicObject
1818
internal DataRow? Row { get; set; }
1919

2020
/// <summary>
21-
///
21+
/// <inheritdoc/>
2222
/// </summary>
2323
/// <param name="propertyName"></param>
2424
/// <returns></returns>
@@ -33,16 +33,16 @@ public class DataTableDynamicObject : DynamicObject
3333
if (!Row.Table.Columns[propertyName]!.AutoIncrement)
3434
{
3535
// 自增长列
36-
Row[propertyName] = Utility.GetPropertyValue(this, propertyName);
36+
Row[propertyName] = Utility.GetPropertyValue(this, propertyName, false);
3737
}
3838
}
3939
ret = Row[propertyName];
4040
}
41-
return ret ?? Utility.GetPropertyValue(this, propertyName);
41+
return ret ?? Utility.GetPropertyValue(this, propertyName, false);
4242
}
4343

4444
/// <summary>
45-
///
45+
/// <inheritdoc/>
4646
/// </summary>
4747
/// <param name="propertyName"></param>
4848
/// <param name="value"></param>

src/BootstrapBlazor/Dynamic/DynamicItemChangedType.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
namespace BootstrapBlazor.Components;
77

88
/// <summary>
9-
///
9+
/// DynamicItemChangedType 类型
1010
/// </summary>
1111
public enum DynamicItemChangedType
1212
{

src/BootstrapBlazor/Dynamic/DynamicObject.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,22 @@ namespace BootstrapBlazor.Components;
1111
public class DynamicObject : IDynamicObject
1212
{
1313
/// <summary>
14-
///
14+
/// <inheritdoc/>
1515
/// </summary>
1616
[AutoGenerateColumn(Ignore = true)]
1717
public Guid DynamicObjectPrimaryKey { get; set; }
1818

1919
/// <summary>
20-
///
20+
/// 获得指定属性值方法
2121
/// </summary>
2222
/// <param name="propertyName"></param>
2323
/// <returns></returns>
24-
public virtual object? GetValue(string propertyName) => Utility.GetPropertyValue(this, propertyName);
24+
public virtual object? GetValue(string propertyName) => Utility.GetPropertyValue(this, propertyName, false);
2525

2626
/// <summary>
27-
///
27+
/// 给指定属性设置值方法
2828
/// </summary>
2929
/// <param name="propertyName"></param>
3030
/// <param name="value"></param>
31-
public virtual void SetValue(string propertyName, object? value) => Utility.SetPropertyValue<object, object?>(this, propertyName, value);
31+
public virtual void SetValue(string propertyName, object? value) => Utility.SetPropertyValue<object, object?>(this, propertyName, value, false);
3232
}

0 commit comments

Comments
 (0)