Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/BootstrapBlazor/BootstrapBlazor.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk.Razor">

<PropertyGroup>
<Version>9.3.1-beta03</Version>
<Version>9.3.1-beta04</Version>
</PropertyGroup>

<ItemGroup>
Expand Down
4 changes: 2 additions & 2 deletions src/BootstrapBlazor/Dynamic/DataTableDynamicContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ private List<IDynamicObject> BuildItems()
{
if (!row.IsNull(col))
{
Utility.SetPropertyValue<object, object?>(d, col.ColumnName, row[col], false);
Utility.SetPropertyValue<object, object?>(d, col.ColumnName, row[col]);
}
}

Expand Down Expand Up @@ -200,7 +200,7 @@ public override async Task AddAsync(IEnumerable<IDynamicObject> selectedItems)
{
if (col.DefaultValue != DBNull.Value)
{
Utility.SetPropertyValue<object, object?>(dynamicObject, col.ColumnName, col.DefaultValue, false);
Utility.SetPropertyValue<object, object?>(dynamicObject, col.ColumnName, col.DefaultValue);
}
}
dynamicObject.Row = row;
Expand Down
4 changes: 2 additions & 2 deletions src/BootstrapBlazor/Dynamic/DataTableDynamicObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/// <summary>
Expand Down
4 changes: 2 additions & 2 deletions src/BootstrapBlazor/Dynamic/DynamicObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ public class DynamicObject : IDynamicObject
/// </summary>
/// <param name="propertyName"></param>
/// <returns></returns>
public virtual object? GetValue(string propertyName) => Utility.GetPropertyValue(this, propertyName, false);
public virtual object? GetValue(string propertyName) => Utility.GetPropertyValue(this, propertyName);

/// <summary>
/// 给指定属性设置值方法
/// </summary>
/// <param name="propertyName"></param>
/// <param name="value"></param>
public virtual void SetValue(string propertyName, object? value) => Utility.SetPropertyValue<object, object?>(this, propertyName, value, false);
public virtual void SetValue(string propertyName, object? value) => Utility.SetPropertyValue<object, object?>(this, propertyName, value);
}
10 changes: 4 additions & 6 deletions src/BootstrapBlazor/Extensions/LambdaExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -620,9 +620,8 @@ private static Expression<Func<TItem, TKey>> GetPropertyLambdaByName<TItem, TKey
/// <typeparam name="TResult"></typeparam>
/// <param name="model"></param>
/// <param name="propertyName"></param>
/// <param name="supportComplexProperty"></param>
/// <returns></returns>
public static Expression<Func<TModel, TResult>> GetPropertyValueLambda<TModel, TResult>(TModel model, string propertyName, bool supportComplexProperty = true)
public static Expression<Func<TModel, TResult>> GetPropertyValueLambda<TModel, TResult>(TModel model, string propertyName)
{
if (model == null)
{
Expand All @@ -631,7 +630,7 @@ public static Expression<Func<TModel, TResult>> GetPropertyValueLambda<TModel, T
var type = model.GetType();
var parameter = Expression.Parameter(typeof(TModel));

return supportComplexProperty && propertyName.Contains('.')
return !type.Assembly.IsDynamic && propertyName.Contains('.')
? GetComplexPropertyExpression()
: GetSimplePropertyExpression();

Expand Down Expand Up @@ -688,9 +687,8 @@ Expression<Func<TModel, TResult>> GetComplexPropertyExpression()
/// <typeparam name="TValue"></typeparam>
/// <param name="model"></param>
/// <param name="propertyName"></param>
/// <param name="supportComplexProperty"></param>
/// <returns></returns>
public static Expression<Action<TModel, TValue>> SetPropertyValueLambda<TModel, TValue>(TModel model, string propertyName, bool supportComplexProperty = true)
public static Expression<Action<TModel, TValue>> SetPropertyValueLambda<TModel, TValue>(TModel model, string propertyName)
{
if (model == null)
{
Expand All @@ -700,7 +698,7 @@ public static Expression<Action<TModel, TValue>> SetPropertyValueLambda<TModel,
var type = model.GetType();
var parameter1 = Expression.Parameter(typeof(TModel));
var parameter2 = Expression.Parameter(typeof(TValue));
return (supportComplexProperty && propertyName.Contains('.'))
return !type.Assembly.IsDynamic && propertyName.Contains('.')
? SetComplexPropertyExpression()
: SetSimplePropertyExpression();

Expand Down
16 changes: 8 additions & 8 deletions src/BootstrapBlazor/Services/CacheManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -513,32 +513,32 @@ public static bool TryGetProperty(Type modelType, string fieldName, [NotNullWhen
return propertyInfo != null;
}

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

private static TResult GetValue<TModel, TResult>(TModel model, string fieldName, bool supportComplexProperty)
private static TResult GetValue<TModel, TResult>(TModel model, string fieldName)
{
if (model == null)
{
throw new ArgumentNullException(nameof(model));
}

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)
{
entry.SetAbsoluteExpiration(TimeSpan.FromSeconds(10));
}

return LambdaExtensions.GetPropertyValueLambda<TModel, TResult>(model, fieldName, supportComplexProperty).Compile();
return LambdaExtensions.GetPropertyValueLambda<TModel, TResult>(model, fieldName).Compile();
});
return invoker(model);
}

public static void SetPropertyValue<TModel, TValue>(TModel model, string fieldName, TValue value, bool supportComplexProperty)
public static void SetPropertyValue<TModel, TValue>(TModel model, string fieldName, TValue value)
{
if (model is IDynamicColumnsObject d)
{
Expand All @@ -552,14 +552,14 @@ public static void SetPropertyValue<TModel, TValue>(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<TModel, TValue>(model, fieldName, supportComplexProperty).Compile();
return LambdaExtensions.SetPropertyValueLambda<TModel, TValue>(model, fieldName).Compile();
});
invoker(model, value);
}
Expand Down
17 changes: 7 additions & 10 deletions src/BootstrapBlazor/Utils/Utility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,20 +108,20 @@ public static class Utility
/// <typeparam name="TResult"></typeparam>
/// <param name="model"></param>
/// <param name="fieldName"></param>
/// <param name="supportComplexProperty"></param>
/// <returns></returns>
public static TResult GetPropertyValue<TModel, TResult>(TModel model, string fieldName, bool supportComplexProperty = true) => CacheManager.GetPropertyValue<TModel, TResult>(model, fieldName, supportComplexProperty);
public static TResult GetPropertyValue<TModel, TResult>(TModel model, string fieldName) => CacheManager.GetPropertyValue<TModel, TResult>(model, fieldName);

/// <summary>
/// 获取 指定对象的属性值
/// </summary>
/// <param name="model"></param>
/// <param name="fieldName"></param>
/// <param name="supportComplexProperty"></param>
/// <returns></returns>
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<object, object?>(model, fieldName);

object? ReflectionInvoke()
{
Expand All @@ -133,8 +133,6 @@ public static class Utility
}
return ret;
}

object? LambdaInvoke() => GetPropertyValue<object, object?>(model, fieldName, supportComplexProperty);
}

/// <summary>
Expand All @@ -145,9 +143,8 @@ public static class Utility
/// <param name="model"></param>
/// <param name="fieldName"></param>
/// <param name="value"></param>
/// <param name="supportComplexProperty"></param>
/// <returns></returns>
public static void SetPropertyValue<TModel, TValue>(TModel model, string fieldName, TValue value, bool supportComplexProperty = true) => CacheManager.SetPropertyValue(model, fieldName, value, supportComplexProperty);
public static void SetPropertyValue<TModel, TValue>(TModel model, string fieldName, TValue value) => CacheManager.SetPropertyValue(model, fieldName, value);

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

/// <summary>
/// 获得指定泛型的 IEditorItem 集合
Expand Down