From ae7a53c99fa41bc6253b04ce5b7929177e138ec4 Mon Sep 17 00:00:00 2001 From: Argo Zhang Date: Fri, 31 Jan 2025 11:12:44 +0800 Subject: [PATCH] refactor(IDynamicObject): remove SupportComplexProperty parameter (#5252) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * refactor: 移除 supportComplexProperty 参数判断 Assembly 是否为动态 * chore: bump version 9.3.1-beta04 --- src/BootstrapBlazor/BootstrapBlazor.csproj | 2 +- .../Dynamic/DataTableDynamicContext.cs | 4 ++-- .../Dynamic/DataTableDynamicObject.cs | 4 ++-- src/BootstrapBlazor/Dynamic/DynamicObject.cs | 4 ++-- .../Extensions/LambdaExtensions.cs | 10 ++++------ src/BootstrapBlazor/Services/CacheManager.cs | 16 ++++++++-------- src/BootstrapBlazor/Utils/Utility.cs | 17 +++++++---------- 7 files changed, 26 insertions(+), 31 deletions(-) diff --git a/src/BootstrapBlazor/BootstrapBlazor.csproj b/src/BootstrapBlazor/BootstrapBlazor.csproj index a377b9c77af..57cfec7cb5f 100644 --- a/src/BootstrapBlazor/BootstrapBlazor.csproj +++ b/src/BootstrapBlazor/BootstrapBlazor.csproj @@ -1,7 +1,7 @@ - 9.3.1-beta03 + 9.3.1-beta04 diff --git a/src/BootstrapBlazor/Dynamic/DataTableDynamicContext.cs b/src/BootstrapBlazor/Dynamic/DataTableDynamicContext.cs index 862afb91e3c..187674547f9 100644 --- a/src/BootstrapBlazor/Dynamic/DataTableDynamicContext.cs +++ b/src/BootstrapBlazor/Dynamic/DataTableDynamicContext.cs @@ -123,7 +123,7 @@ private List BuildItems() { if (!row.IsNull(col)) { - Utility.SetPropertyValue(d, col.ColumnName, row[col], false); + Utility.SetPropertyValue(d, col.ColumnName, row[col]); } } @@ -200,7 +200,7 @@ public override async Task AddAsync(IEnumerable selectedItems) { if (col.DefaultValue != DBNull.Value) { - Utility.SetPropertyValue(dynamicObject, col.ColumnName, col.DefaultValue, false); + Utility.SetPropertyValue(dynamicObject, col.ColumnName, col.DefaultValue); } } dynamicObject.Row = row; diff --git a/src/BootstrapBlazor/Dynamic/DataTableDynamicObject.cs b/src/BootstrapBlazor/Dynamic/DataTableDynamicObject.cs index 4d40c0a763d..343443cac83 100644 --- a/src/BootstrapBlazor/Dynamic/DataTableDynamicObject.cs +++ b/src/BootstrapBlazor/Dynamic/DataTableDynamicObject.cs @@ -33,12 +33,12 @@ public class DataTableDynamicObject : DynamicObject if (!Row.Table.Columns[propertyName]!.AutoIncrement) { // 自增长列 - Row[propertyName] = Utility.GetPropertyValue(this, propertyName, false); + Row[propertyName] = Utility.GetPropertyValue(this, propertyName); } } ret = Row[propertyName]; } - return ret ?? Utility.GetPropertyValue(this, propertyName, false); + return ret ?? Utility.GetPropertyValue(this, propertyName); } /// diff --git a/src/BootstrapBlazor/Dynamic/DynamicObject.cs b/src/BootstrapBlazor/Dynamic/DynamicObject.cs index 047da1e1e56..15f574e094d 100644 --- a/src/BootstrapBlazor/Dynamic/DynamicObject.cs +++ b/src/BootstrapBlazor/Dynamic/DynamicObject.cs @@ -21,12 +21,12 @@ public class DynamicObject : IDynamicObject /// /// /// - public virtual object? GetValue(string propertyName) => Utility.GetPropertyValue(this, propertyName, false); + public virtual object? GetValue(string propertyName) => Utility.GetPropertyValue(this, propertyName); /// /// 给指定属性设置值方法 /// /// /// - public virtual void SetValue(string propertyName, object? value) => Utility.SetPropertyValue(this, propertyName, value, false); + public virtual void SetValue(string propertyName, object? value) => Utility.SetPropertyValue(this, propertyName, value); } diff --git a/src/BootstrapBlazor/Extensions/LambdaExtensions.cs b/src/BootstrapBlazor/Extensions/LambdaExtensions.cs index 49217a51210..8a19cf6a38e 100644 --- a/src/BootstrapBlazor/Extensions/LambdaExtensions.cs +++ b/src/BootstrapBlazor/Extensions/LambdaExtensions.cs @@ -620,9 +620,8 @@ private static Expression> GetPropertyLambdaByName /// /// - /// /// - public static Expression> GetPropertyValueLambda(TModel model, string propertyName, bool supportComplexProperty = true) + public static Expression> GetPropertyValueLambda(TModel model, string propertyName) { if (model == null) { @@ -631,7 +630,7 @@ public static Expression> GetPropertyValueLambda> GetComplexPropertyExpression() /// /// /// - /// /// - public static Expression> SetPropertyValueLambda(TModel model, string propertyName, bool supportComplexProperty = true) + public static Expression> SetPropertyValueLambda(TModel model, string propertyName) { if (model == null) { @@ -700,7 +698,7 @@ public static Expression> SetPropertyValueLambda(TModel model, string fieldName, bool supportComplexProperty) => (model is IDynamicColumnsObject d) + public static TResult GetPropertyValue(TModel model, string fieldName) => (model is IDynamicColumnsObject d) ? (TResult)d.GetValue(fieldName)! - : GetValue(model, fieldName, supportComplexProperty); + : GetValue(model, fieldName); - private static TResult GetValue(TModel model, string fieldName, bool supportComplexProperty) + private static TResult GetValue(TModel model, string fieldName) { if (model == null) { @@ -525,7 +525,7 @@ private static TResult GetValue(TModel model, string fieldName, } var type = model.GetType(); - var cacheKey = $"{CacheKeyPrefix}-Lambda-Get-{type.GetUniqueTypeName()}-{typeof(TModel)}-{fieldName}-{typeof(TResult)}-{supportComplexProperty}"; + var cacheKey = $"{CacheKeyPrefix}-Lambda-Get-{type.GetUniqueTypeName()}-{typeof(TModel)}-{fieldName}-{typeof(TResult)}"; var invoker = Instance.GetOrCreate(cacheKey, entry => { if (type.Assembly.IsDynamic) @@ -533,12 +533,12 @@ private static TResult GetValue(TModel model, string fieldName, entry.SetAbsoluteExpiration(TimeSpan.FromSeconds(10)); } - return LambdaExtensions.GetPropertyValueLambda(model, fieldName, supportComplexProperty).Compile(); + return LambdaExtensions.GetPropertyValueLambda(model, fieldName).Compile(); }); return invoker(model); } - public static void SetPropertyValue(TModel model, string fieldName, TValue value, bool supportComplexProperty) + public static void SetPropertyValue(TModel model, string fieldName, TValue value) { if (model is IDynamicColumnsObject d) { @@ -552,14 +552,14 @@ public static void SetPropertyValue(TModel model, string fieldNa } var type = model.GetType(); - var cacheKey = $"{CacheKeyPrefix}-Lambda-Set-{type.GetUniqueTypeName()}-{typeof(TModel)}-{fieldName}-{typeof(TValue)}-{supportComplexProperty}"; + var cacheKey = $"{CacheKeyPrefix}-Lambda-Set-{type.GetUniqueTypeName()}-{typeof(TModel)}-{fieldName}-{typeof(TValue)}"; var invoker = Instance.GetOrCreate(cacheKey, entry => { if (type.Assembly.IsDynamic) { entry.SetAbsoluteExpiration(TimeSpan.FromSeconds(10)); } - return LambdaExtensions.SetPropertyValueLambda(model, fieldName, supportComplexProperty).Compile(); + return LambdaExtensions.SetPropertyValueLambda(model, fieldName).Compile(); }); invoker(model, value); } diff --git a/src/BootstrapBlazor/Utils/Utility.cs b/src/BootstrapBlazor/Utils/Utility.cs index 75b6911cc8b..20d61864124 100644 --- a/src/BootstrapBlazor/Utils/Utility.cs +++ b/src/BootstrapBlazor/Utils/Utility.cs @@ -108,20 +108,20 @@ public static class Utility /// /// /// - /// /// - public static TResult GetPropertyValue(TModel model, string fieldName, bool supportComplexProperty = true) => CacheManager.GetPropertyValue(model, fieldName, supportComplexProperty); + public static TResult GetPropertyValue(TModel model, string fieldName) => CacheManager.GetPropertyValue(model, fieldName); /// /// 获取 指定对象的属性值 /// /// /// - /// /// - public static object? GetPropertyValue(object model, string fieldName, bool supportComplexProperty = true) + public static object? GetPropertyValue(object model, string fieldName) { - return model.GetType().Assembly.IsDynamic ? ReflectionInvoke() : LambdaInvoke(); + return model.GetType().Assembly.IsDynamic + ? ReflectionInvoke() + : GetPropertyValue(model, fieldName); object? ReflectionInvoke() { @@ -133,8 +133,6 @@ public static class Utility } return ret; } - - object? LambdaInvoke() => GetPropertyValue(model, fieldName, supportComplexProperty); } /// @@ -145,9 +143,8 @@ public static class Utility /// /// /// - /// /// - public static void SetPropertyValue(TModel model, string fieldName, TValue value, bool supportComplexProperty = true) => CacheManager.SetPropertyValue(model, fieldName, value, supportComplexProperty); + public static void SetPropertyValue(TModel model, string fieldName, TValue value) => CacheManager.SetPropertyValue(model, fieldName, value); /// /// 获得 排序方法 @@ -869,7 +866,7 @@ static Expression> CreateLambda(Type /// /// /// - public static EventCallback CreateCallback(ComponentBase component, object model, string fieldName) => EventCallback.Factory.Create(component, t => CacheManager.SetPropertyValue(model, fieldName, t, true)); + public static EventCallback CreateCallback(ComponentBase component, object model, string fieldName) => EventCallback.Factory.Create(component, t => CacheManager.SetPropertyValue(model, fieldName, t)); /// /// 获得指定泛型的 IEditorItem 集合