PrpertyHelper; ICustomForeignKey

This commit is contained in:
Loretta 2025-10-11 17:51:58 +02:00
parent 9657e7449f
commit 7609e94f18
2 changed files with 36 additions and 0 deletions

View File

@ -0,0 +1,24 @@
using System.Collections;
using System.Reflection;
namespace AyCode.Core.Extensions;
public static class PropertyHelper
{
public static TDestination CopyPublicProperties<TSource, TDestination>(TSource src, TDestination dest)
{
if (src == null || dest == null) return dest;
var srcProps = typeof(TSource).GetProperties(BindingFlags.Public | BindingFlags.Instance).Where(p => p.CanRead);
foreach (var sp in srcProps)
{
var dp = typeof(TDestination).GetProperty(sp.Name, BindingFlags.Public | BindingFlags.Instance);
if (dp == null || !dp.CanWrite || dp is IEnumerable) continue;
dp.SetValue(dest, sp.GetValue(src));
}
return dest;
}
}

View File

@ -0,0 +1,12 @@
namespace AyCode.Interfaces;
public interface ICustomForeignKeyInt : ICustomForeignKey<int>
{ }
public interface ICustomForeignKeyGuid : ICustomForeignKey<Guid>
{ }
public interface ICustomForeignKey<out T>
{
T ForeignKey { get; }
}