mirror of
https://github.com/LD-Reborn/Berufsschule_HAM.git
synced 2025-12-20 23:11:54 +00:00
32 lines
993 B
C#
32 lines
993 B
C#
namespace Berufsschule_HAM.Helpers;
|
|
|
|
public static class AttributesHelper
|
|
{
|
|
public static void UpdateNonNullProperties(object source, object target)
|
|
{
|
|
if (source == null || target == null) return;
|
|
|
|
var sourceProperties = source.GetType().GetProperties();
|
|
var targetProperties = target.GetType().GetProperties();
|
|
|
|
foreach (var sourceProperty in sourceProperties)
|
|
{
|
|
if (sourceProperty.CanRead)
|
|
{
|
|
var sourceValue = sourceProperty.GetValue(source);
|
|
|
|
if (sourceValue == null) continue;
|
|
|
|
var targetProperty = targetProperties.FirstOrDefault(p =>
|
|
p.Name == sourceProperty.Name &&
|
|
p.CanWrite &&
|
|
p.PropertyType == sourceProperty.PropertyType);
|
|
|
|
if (targetProperty != null)
|
|
{
|
|
targetProperty.SetValue(target, sourceValue);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
} |