Initial version

This commit is contained in:
2026-06-09 22:27:38 +02:00
parent 5afbf3b01c
commit 5ff2ac8941
57 changed files with 2343 additions and 98 deletions
+34
View File
@@ -0,0 +1,34 @@
namespace EonaCat.gRPC.Api.Helpers;
public static class CustomMapper
{
/// <summary>
/// Proto to Entity/DTO And Reverse
/// </summary>
/// <typeparam name="TSource"></typeparam>
/// <typeparam name="TDestination"></typeparam>
/// <param name="src"></param>
/// <returns>TDestination</returns>
public static TDestination Map<TSource, TDestination>(TSource src) where TDestination : new()
{
try
{
var tDest = (TDestination)Activator.CreateInstance(typeof(TDestination))!;
if (src == null)
return tDest;
var srcClassType = src.GetType();
var srcProperties = srcClassType.GetProperties();
foreach (var srcProperty in srcProperties)
{
var destPropertyInfo = tDest.GetType().GetProperty(srcProperty.Name);
if (srcProperty.GetType() == destPropertyInfo?.GetType())
destPropertyInfo.SetValue(tDest, srcProperty.GetValue(src, null), null);
}
return tDest;
}
catch (Exception e)
{
throw new Exception($"Unsupported mapping.\n{e.Message}");
}
}
}