Skip to content

Commit 332b160

Browse files
committed
revert: 撤销部分代码
1 parent 8f83b24 commit 332b160

1 file changed

Lines changed: 14 additions & 56 deletions

File tree

src/BootstrapBlazor/Utils/Utility.cs

Lines changed: 14 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -757,11 +757,11 @@ public static void CreateComponentByFieldType(this RenderTreeBuilder builder, Co
757757
{
758758
builder.AddAttribute(70, nameof(ValidateBase<>.ShowLabelTooltip), item.ShowLabelTooltip);
759759
}
760-
}
761760

762-
if (skipValidate is true)
763-
{
764-
builder.AddAttribute(71, nameof(ValidateBase<>.SkipValidate), true);
761+
if (skipValidate is true)
762+
{
763+
builder.AddAttribute(71, nameof(ValidateBase<>.SkipValidate), true);
764+
}
765765
}
766766

767767
if (componentType == typeof(NullSwitch) && TryGetProperty(model.GetType(), fieldName, out var propertyInfo))
@@ -1187,19 +1187,19 @@ public static string Format(object? source, IFormatProvider provider)
11871187
/// </param>
11881188
public static object GenerateValueChanged(ComponentBase component, object model, string fieldName, Type fieldType)
11891189
{
1190-
var valueChangedInvoker = CreateValueChangedLambda(fieldType).Compile();
1190+
var valueChangedInvoker = CreateLambda(fieldType).Compile();
11911191
return valueChangedInvoker(component, model, fieldName);
1192-
}
11931192

1194-
static Expression<Func<ComponentBase, object, string, object>> CreateValueChangedLambda(Type fieldType)
1195-
{
1196-
var exp_p1 = Expression.Parameter(typeof(ComponentBase));
1197-
var exp_p2 = Expression.Parameter(typeof(object));
1198-
var exp_p3 = Expression.Parameter(typeof(string));
1199-
var method = typeof(Utility).GetMethod(nameof(CreateCallback), BindingFlags.Static | BindingFlags.Public)!.MakeGenericMethod(fieldType);
1200-
var body = Expression.Call(null, method, exp_p1, exp_p2, exp_p3);
1193+
static Expression<Func<ComponentBase, object, string, object>> CreateLambda(Type fieldType)
1194+
{
1195+
var exp_p1 = Expression.Parameter(typeof(ComponentBase));
1196+
var exp_p2 = Expression.Parameter(typeof(object));
1197+
var exp_p3 = Expression.Parameter(typeof(string));
1198+
var method = typeof(Utility).GetMethod(nameof(CreateCallback), BindingFlags.Static | BindingFlags.Public)!.MakeGenericMethod(fieldType);
1199+
var body = Expression.Call(null, method, exp_p1, exp_p2, exp_p3);
12011200

1202-
return Expression.Lambda<Func<ComponentBase, object, string, object>>(Expression.Convert(body, typeof(object)), exp_p1, exp_p2, exp_p3);
1201+
return Expression.Lambda<Func<ComponentBase, object, string, object>>(Expression.Convert(body, typeof(object)), exp_p1, exp_p2, exp_p3);
1202+
}
12031203
}
12041204

12051205
/// <summary>
@@ -1224,48 +1224,6 @@ static Expression<Func<ComponentBase, object, string, object>> CreateValueChange
12241224
/// </param>
12251225
public static EventCallback<TType> CreateCallback<TType>(ComponentBase component, object model, string fieldName) => EventCallback.Factory.Create<TType>(component, t => CacheManager.SetPropertyValue(model, fieldName, t));
12261226

1227-
/// <summary>
1228-
/// <para lang="zh">获得 OnValueChanged 回调委托</para>
1229-
/// <para lang="en">Get OnValueChanged callback delegate</para>
1230-
/// </summary>
1231-
/// <param name="model">
1232-
/// <para lang="zh">模型实例</para>
1233-
/// <para lang="en">Model instance</para>
1234-
/// </param>
1235-
/// <param name="fieldName">
1236-
/// <para lang="zh">字段名称</para>
1237-
/// <para lang="en">Field name</para>
1238-
/// </param>
1239-
/// <param name="fieldType">
1240-
/// <para lang="zh">字段类型</para>
1241-
/// <para lang="en">Field type</para>
1242-
/// </param>
1243-
public static object GenerateOnValueChanged(object model, string fieldName, Type fieldType)
1244-
{
1245-
var valueChangedInvoker = CreateDynamicObjectOnValueChangedLambda(fieldType).Compile();
1246-
return valueChangedInvoker(model, fieldName);
1247-
}
1248-
1249-
static Expression<Func<object, string, object>> CreateDynamicObjectOnValueChangedLambda(Type fieldType)
1250-
{
1251-
var exp_p1 = Expression.Parameter(typeof(object));
1252-
var exp_p2 = Expression.Parameter(typeof(string));
1253-
var method = typeof(Utility).GetMethod(nameof(CreateDynamicObjectOnValueChangedCallback), BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic)!.MakeGenericMethod(fieldType);
1254-
var body = Expression.Call(null, method, exp_p1, exp_p2);
1255-
1256-
return Expression.Lambda<Func<object, string, object>>(Expression.Convert(body, typeof(object)), exp_p1, exp_p2);
1257-
}
1258-
1259-
static Func<TValue?, Task> CreateDynamicObjectOnValueChangedCallback<TValue>(object model, string fieldName) => v =>
1260-
{
1261-
if (model is IDynamicObject d)
1262-
{
1263-
d.SetValue(fieldName, v);
1264-
}
1265-
1266-
return Task.CompletedTask;
1267-
};
1268-
12691227
/// <summary>
12701228
/// <para lang="zh">获得指定泛型的 IEditorItem 集合</para>
12711229
/// <para lang="en">Get IEditorItem collection of specified generic type</para>

0 commit comments

Comments
 (0)