diff --git a/AyCode.Core/Extensions/PropertyHelper.cs b/AyCode.Core/Extensions/PropertyHelper.cs new file mode 100644 index 0000000..a2078a4 --- /dev/null +++ b/AyCode.Core/Extensions/PropertyHelper.cs @@ -0,0 +1,24 @@ +using System.Collections; +using System.Reflection; + +namespace AyCode.Core.Extensions; + +public static class PropertyHelper +{ + public static TDestination CopyPublicProperties(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; + } +} \ No newline at end of file diff --git a/AyCode.Interfaces/ICustomForeignKey.cs b/AyCode.Interfaces/ICustomForeignKey.cs new file mode 100644 index 0000000..7851f33 --- /dev/null +++ b/AyCode.Interfaces/ICustomForeignKey.cs @@ -0,0 +1,12 @@ +namespace AyCode.Interfaces; + +public interface ICustomForeignKeyInt : ICustomForeignKey +{ } + +public interface ICustomForeignKeyGuid : ICustomForeignKey +{ } + +public interface ICustomForeignKey +{ + T ForeignKey { get; } +} \ No newline at end of file