mirror of
https://github.com/LD-Reborn/Berufsschule_HAM.git
synced 2025-12-20 06:51:55 +00:00
Added Make and Model and Attributes to AssetDescription
This commit is contained in:
32
src/Helpers/AttributesHelper.cs
Normal file
32
src/Helpers/AttributesHelper.cs
Normal file
@@ -0,0 +1,32 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user