Skip to content

Commit ae7a53c

Browse files
authored
refactor(IDynamicObject): remove SupportComplexProperty parameter (#5252)
* refactor: 移除 supportComplexProperty 参数判断 Assembly 是否为动态 * chore: bump version 9.3.1-beta04
1 parent a8b3118 commit ae7a53c

File tree

7 files changed

+26
-31
lines changed

7 files changed

+26
-31
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-beta03</Version>
4+
<Version>9.3.1-beta04</Version>
55
</PropertyGroup>
66

77
<ItemGroup>

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], false);
126+
Utility.SetPropertyValue<object, object?>(d, col.ColumnName, row[col]);
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, false);
203+
Utility.SetPropertyValue<object, object?>(dynamicObject, col.ColumnName, col.DefaultValue);
204204
}
205205
}
206206
dynamicObject.Row = row;

src/BootstrapBlazor/Dynamic/DataTableDynamicObject.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,12 @@ public class DataTableDynamicObject : DynamicObject
3333
if (!Row.Table.Columns[propertyName]!.AutoIncrement)
3434
{
3535
// 自增长列
36-
Row[propertyName] = Utility.GetPropertyValue(this, propertyName, false);
36+
Row[propertyName] = Utility.GetPropertyValue(this, propertyName);
3737
}
3838
}
3939
ret = Row[propertyName];
4040
}
41-
return ret ?? Utility.GetPropertyValue(this, propertyName, false);
41+
return ret ?? Utility.GetPropertyValue(this, propertyName);
4242
}
4343

4444
/// <summary>

src/BootstrapBlazor/Dynamic/DynamicObject.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,12 @@ public class DynamicObject : IDynamicObject
2121
/// </summary>
2222
/// <param name="propertyName"></param>
2323
/// <returns></returns>
24-
public virtual object? GetValue(string propertyName) => Utility.GetPropertyValue(this, propertyName, false);
24+
public virtual object? GetValue(string propertyName) => Utility.GetPropertyValue(this, propertyName);
2525

2626
/// <summary>
2727
/// 给指定属性设置值方法
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, false);
31+
public virtual void SetValue(string propertyName, object? value) => Utility.SetPropertyValue<object, object?>(this, propertyName, value);
3232
}

src/BootstrapBlazor/Extensions/LambdaExtensions.cs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -620,9 +620,8 @@ private static Expression<Func<TItem, TKey>> GetPropertyLambdaByName<TItem, TKey
620620
/// <typeparam name="TResult"></typeparam>
621621
/// <param name="model"></param>
622622
/// <param name="propertyName"></param>
623-
/// <param name="supportComplexProperty"></param>
624623
/// <returns></returns>
625-
public static Expression<Func<TModel, TResult>> GetPropertyValueLambda<TModel, TResult>(TModel model, string propertyName, bool supportComplexProperty = true)
624+
public static Expression<Func<TModel, TResult>> GetPropertyValueLambda<TModel, TResult>(TModel model, string propertyName)
626625
{
627626
if (model == null)
628627
{
@@ -631,7 +630,7 @@ public static Expression<Func<TModel, TResult>> GetPropertyValueLambda<TModel, T
631630
var type = model.GetType();
632631
var parameter = Expression.Parameter(typeof(TModel));
633632

634-
return supportComplexProperty && propertyName.Contains('.')
633+
return !type.Assembly.IsDynamic && propertyName.Contains('.')
635634
? GetComplexPropertyExpression()
636635
: GetSimplePropertyExpression();
637636

@@ -688,9 +687,8 @@ Expression<Func<TModel, TResult>> GetComplexPropertyExpression()
688687
/// <typeparam name="TValue"></typeparam>
689688
/// <param name="model"></param>
690689
/// <param name="propertyName"></param>
691-
/// <param name="supportComplexProperty"></param>
692690
/// <returns></returns>
693-
public static Expression<Action<TModel, TValue>> SetPropertyValueLambda<TModel, TValue>(TModel model, string propertyName, bool supportComplexProperty = true)
691+
public static Expression<Action<TModel, TValue>> SetPropertyValueLambda<TModel, TValue>(TModel model, string propertyName)
694692
{
695693
if (model == null)
696694
{
@@ -700,7 +698,7 @@ public static Expression<Action<TModel, TValue>> SetPropertyValueLambda<TModel,
700698
var type = model.GetType();
701699
var parameter1 = Expression.Parameter(typeof(TModel));
702700
var parameter2 = Expression.Parameter(typeof(TValue));
703-
return (supportComplexProperty && propertyName.Contains('.'))
701+
return !type.Assembly.IsDynamic && propertyName.Contains('.')
704702
? SetComplexPropertyExpression()
705703
: SetSimplePropertyExpression();
706704

src/BootstrapBlazor/Services/CacheManager.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -513,32 +513,32 @@ public static bool TryGetProperty(Type modelType, string fieldName, [NotNullWhen
513513
return propertyInfo != null;
514514
}
515515

516-
public static TResult GetPropertyValue<TModel, TResult>(TModel model, string fieldName, bool supportComplexProperty) => (model is IDynamicColumnsObject d)
516+
public static TResult GetPropertyValue<TModel, TResult>(TModel model, string fieldName) => (model is IDynamicColumnsObject d)
517517
? (TResult)d.GetValue(fieldName)!
518-
: GetValue<TModel, TResult>(model, fieldName, supportComplexProperty);
518+
: GetValue<TModel, TResult>(model, fieldName);
519519

520-
private static TResult GetValue<TModel, TResult>(TModel model, string fieldName, bool supportComplexProperty)
520+
private static TResult GetValue<TModel, TResult>(TModel model, string fieldName)
521521
{
522522
if (model == null)
523523
{
524524
throw new ArgumentNullException(nameof(model));
525525
}
526526

527527
var type = model.GetType();
528-
var cacheKey = $"{CacheKeyPrefix}-Lambda-Get-{type.GetUniqueTypeName()}-{typeof(TModel)}-{fieldName}-{typeof(TResult)}-{supportComplexProperty}";
528+
var cacheKey = $"{CacheKeyPrefix}-Lambda-Get-{type.GetUniqueTypeName()}-{typeof(TModel)}-{fieldName}-{typeof(TResult)}";
529529
var invoker = Instance.GetOrCreate(cacheKey, entry =>
530530
{
531531
if (type.Assembly.IsDynamic)
532532
{
533533
entry.SetAbsoluteExpiration(TimeSpan.FromSeconds(10));
534534
}
535535

536-
return LambdaExtensions.GetPropertyValueLambda<TModel, TResult>(model, fieldName, supportComplexProperty).Compile();
536+
return LambdaExtensions.GetPropertyValueLambda<TModel, TResult>(model, fieldName).Compile();
537537
});
538538
return invoker(model);
539539
}
540540

541-
public static void SetPropertyValue<TModel, TValue>(TModel model, string fieldName, TValue value, bool supportComplexProperty)
541+
public static void SetPropertyValue<TModel, TValue>(TModel model, string fieldName, TValue value)
542542
{
543543
if (model is IDynamicColumnsObject d)
544544
{
@@ -552,14 +552,14 @@ public static void SetPropertyValue<TModel, TValue>(TModel model, string fieldNa
552552
}
553553

554554
var type = model.GetType();
555-
var cacheKey = $"{CacheKeyPrefix}-Lambda-Set-{type.GetUniqueTypeName()}-{typeof(TModel)}-{fieldName}-{typeof(TValue)}-{supportComplexProperty}";
555+
var cacheKey = $"{CacheKeyPrefix}-Lambda-Set-{type.GetUniqueTypeName()}-{typeof(TModel)}-{fieldName}-{typeof(TValue)}";
556556
var invoker = Instance.GetOrCreate(cacheKey, entry =>
557557
{
558558
if (type.Assembly.IsDynamic)
559559
{
560560
entry.SetAbsoluteExpiration(TimeSpan.FromSeconds(10));
561561
}
562-
return LambdaExtensions.SetPropertyValueLambda<TModel, TValue>(model, fieldName, supportComplexProperty).Compile();
562+
return LambdaExtensions.SetPropertyValueLambda<TModel, TValue>(model, fieldName).Compile();
563563
});
564564
invoker(model, value);
565565
}

src/BootstrapBlazor/Utils/Utility.cs

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -108,20 +108,20 @@ public static class Utility
108108
/// <typeparam name="TResult"></typeparam>
109109
/// <param name="model"></param>
110110
/// <param name="fieldName"></param>
111-
/// <param name="supportComplexProperty"></param>
112111
/// <returns></returns>
113-
public static TResult GetPropertyValue<TModel, TResult>(TModel model, string fieldName, bool supportComplexProperty = true) => CacheManager.GetPropertyValue<TModel, TResult>(model, fieldName, supportComplexProperty);
112+
public static TResult GetPropertyValue<TModel, TResult>(TModel model, string fieldName) => CacheManager.GetPropertyValue<TModel, TResult>(model, fieldName);
114113

115114
/// <summary>
116115
/// 获取 指定对象的属性值
117116
/// </summary>
118117
/// <param name="model"></param>
119118
/// <param name="fieldName"></param>
120-
/// <param name="supportComplexProperty"></param>
121119
/// <returns></returns>
122-
public static object? GetPropertyValue(object model, string fieldName, bool supportComplexProperty = true)
120+
public static object? GetPropertyValue(object model, string fieldName)
123121
{
124-
return model.GetType().Assembly.IsDynamic ? ReflectionInvoke() : LambdaInvoke();
122+
return model.GetType().Assembly.IsDynamic
123+
? ReflectionInvoke()
124+
: GetPropertyValue<object, object?>(model, fieldName);
125125

126126
object? ReflectionInvoke()
127127
{
@@ -133,8 +133,6 @@ public static class Utility
133133
}
134134
return ret;
135135
}
136-
137-
object? LambdaInvoke() => GetPropertyValue<object, object?>(model, fieldName, supportComplexProperty);
138136
}
139137

140138
/// <summary>
@@ -145,9 +143,8 @@ public static class Utility
145143
/// <param name="model"></param>
146144
/// <param name="fieldName"></param>
147145
/// <param name="value"></param>
148-
/// <param name="supportComplexProperty"></param>
149146
/// <returns></returns>
150-
public static void SetPropertyValue<TModel, TValue>(TModel model, string fieldName, TValue value, bool supportComplexProperty = true) => CacheManager.SetPropertyValue(model, fieldName, value, supportComplexProperty);
147+
public static void SetPropertyValue<TModel, TValue>(TModel model, string fieldName, TValue value) => CacheManager.SetPropertyValue(model, fieldName, value);
151148

152149
/// <summary>
153150
/// 获得 排序方法
@@ -869,7 +866,7 @@ static Expression<Func<ComponentBase, object, string, object>> CreateLambda(Type
869866
/// <param name="model"></param>
870867
/// <param name="fieldName"></param>
871868
/// <returns></returns>
872-
public static EventCallback<TType> CreateCallback<TType>(ComponentBase component, object model, string fieldName) => EventCallback.Factory.Create<TType>(component, t => CacheManager.SetPropertyValue(model, fieldName, t, true));
869+
public static EventCallback<TType> CreateCallback<TType>(ComponentBase component, object model, string fieldName) => EventCallback.Factory.Create<TType>(component, t => CacheManager.SetPropertyValue(model, fieldName, t));
873870

874871
/// <summary>
875872
/// 获得指定泛型的 IEditorItem 集合

0 commit comments

Comments
 (0)