Files
BITFALL/Assets/BITKit/Core/AutoMapper/BITMapper.cs
CortexCore 0b66b0a19e 1
2024-08-11 12:46:15 +08:00

29 lines
1003 B
C#

namespace BITKit
{
public static class BITMapper
{
public static void Map<T>(T source, T target) where T : class
{
foreach (var info in source.GetType().GetProperties(ReflectionHelper.Flags))
{
if (info.CanWrite is false) continue;
var targetInfo = target.GetType().GetProperty(info.Name, ReflectionHelper.Flags);
var value = info.GetValue(source);
if (value is not null)
{
targetInfo?.SetValue(target,value );
}
}
foreach (var info in source.GetType().GetFields(ReflectionHelper.Flags))
{
var targetInfo = target.GetType().GetField(info.Name, ReflectionHelper.Flags);
var value = info.GetValue(source);
if (value is not null)
{
targetInfo?.SetValue(target, value);
}
}
}
}
}