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