This commit is contained in:
DEVICE8\12494
2023-05-18 18:44:16 +08:00
parent 82c94d9707
commit 9d30038a7d
23 changed files with 618 additions and 166 deletions

View File

@@ -2,22 +2,22 @@
namespace Tnb.EquipMgr.Utils
{
public class PropertySet<T>
{
public static Dictionary<string, Action<object, object>> ValueFactories = new Dictionary<string, Action<object, object>>(StringComparer.OrdinalIgnoreCase);
//public class PropertySet<T>
//{
// public static Dictionary<string, Action<object, object>> ValueFactories = new Dictionary<string, Action<object, object>>(StringComparer.OrdinalIgnoreCase);
public static Action<object, object> CreateSetPropertyValueAction(string propertyName)
{
var property = typeof(T).GetProperty(propertyName);
var target = Expression.Parameter(typeof(object));
var propertyValue = Expression.Parameter(typeof(object));
var castTarget = Expression.Convert(target, typeof(T));
var castPropertyValue = Expression.Convert(propertyValue, property!.PropertyType);
var setPropertyValue = Expression.Call(castTarget, property.GetSetMethod()!, castPropertyValue);
return Expression.Lambda<Action<object, object>>(setPropertyValue, target, propertyValue).Compile();
}
// public static Action<object, object> CreateSetPropertyValueAction(string propertyName)
// {
// var property = typeof(T).GetProperty(propertyName);
// var target = Expression.Parameter(typeof(object));
// var propertyValue = Expression.Parameter(typeof(object));
// var castTarget = Expression.Convert(target, typeof(T));
// var castPropertyValue = Expression.Convert(propertyValue, property!.PropertyType);
// var setPropertyValue = Expression.Call(castTarget, property.GetSetMethod()!, castPropertyValue);
// return Expression.Lambda<Action<object, object>>(setPropertyValue, target, propertyValue).Compile();
// }
}
//}
}