ExpandProperties扩展方法增加目标对象和SetValue方法。

This commit is contained in:
FalconFly 2023-06-21 09:34:51 +08:00
parent ef717dfca5
commit 1918c13112

View File

@ -86,9 +86,11 @@ namespace Falcon.SugarApi
public static IEnumerable<ExpandPropertyInfo> ExpandProperties(this object obj) {
foreach(PropertyInfo p in obj.GetType().GetProperties()) {
yield return new ExpandPropertyInfo {
TargetObj = obj,
Name = p.Name,
Type = p.PropertyType,
Value = p.CanRead ? p.GetValue(obj) : null,
SetValue = new Action<Object?>(v => p.SetValue(obj,v)),
};
}
}
@ -176,6 +178,10 @@ namespace Falcon.SugarApi
/// </summary>
public class ExpandPropertyInfo
{
/// <summary>
/// 目标对象
/// </summary>
public object TargetObj { get; set; }
/// <summary>
/// 属性名
/// </summary>
@ -188,6 +194,10 @@ namespace Falcon.SugarApi
/// 属性值
/// </summary>
public object? Value { get; set; }
/// <summary>
/// 设置对象值
/// </summary>
public Action<object?> SetValue { get; set; }
}
/// <summary>