根据生产bom拆分子工单代码调整

This commit is contained in:
DEVICE8\12494
2023-05-24 23:31:13 +08:00
parent 65072abc04
commit d12e05d737
16 changed files with 336 additions and 98 deletions

View File

@@ -18,11 +18,22 @@ namespace JNPF.Common.Extension
}
setAction(instance, value);
}
public static void PropertySetValue<T>(this T instance, string propertyName, object value)
{
if (!PropertySet<T>.ValueFactories2.TryGetValue(propertyName, out Action<T, object> setAction))
{
setAction = PropertySet<T>.CreateSetPropertyValueAction2(propertyName);
PropertySet<T>.ValueFactories2.Add(propertyName, setAction);
}
setAction(instance, value);
}
}
public class PropertySet<T>
{
public static Dictionary<string, Action<object, object>> ValueFactories = new Dictionary<string, Action<object, object>>(StringComparer.OrdinalIgnoreCase);
public static Dictionary<string, Action<T, object>> ValueFactories2 = new Dictionary<string, Action<T, object>>(StringComparer.OrdinalIgnoreCase);
public static Action<object, object> CreateSetPropertyValueAction(string propertyName)
{
@@ -35,5 +46,17 @@ namespace JNPF.Common.Extension
return Expression.Lambda<Action<object, object>>(setPropertyValue, target, propertyValue).Compile();
}
public static Action<T, object> CreateSetPropertyValueAction2(string propertyName)
{
var property = typeof(T).GetProperty(propertyName);
var target = Expression.Parameter(typeof(T));
var propExp = Expression.Property(target, propertyName);
var propertyValue = Expression.Parameter(typeof(object));
var castPropertyValue = Expression.Convert(propertyValue, property!.PropertyType);
var assignExp = Expression.Assign(propExp, castPropertyValue);
return Expression.Lambda<Action<T, object>>(assignExp, new[] { target,propertyValue }).Compile();
}
}
}