PrpertyHelper; ICustomForeignKey
This commit is contained in:
parent
9657e7449f
commit
7609e94f18
|
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -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; }
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue