This commit is contained in:
CortexCore
2024-07-29 14:56:29 +08:00
parent d044175e77
commit f46602d4a4
2 changed files with 21 additions and 4 deletions

View File

@@ -4,13 +4,16 @@
{
public static void Map<T>(T source, T target) where T : class
{
foreach (var info in typeof(T).GetProperties())
foreach (var info in source.GetType().GetProperties(ReflectionHelper.Flags))
{
info.SetValue(source, info.GetValue(target));
if (info.CanWrite is false) continue;
var targetInfo = target.GetType().GetProperty(info.Name, ReflectionHelper.Flags);
targetInfo?.SetValue(target, info.GetValue(source));
}
foreach (var info in typeof(T).GetFields())
foreach (var info in source.GetType().GetFields(ReflectionHelper.Flags))
{
info.SetValue(source, info.GetValue(target));
var targetInfo = target.GetType().GetField(info.Name, ReflectionHelper.Flags);
targetInfo?.SetValue(target, info.GetValue(source));
}
}
}