From 339dc635e54156e73491c13a5921201e38ae683b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matija=20Ko=C5=BEelj?= Date: Tue, 24 Jan 2023 16:48:25 +0100 Subject: [PATCH] Add clone method to EntityExtensions --- src/Connected.Entities/EntitiesExtensions.cs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/Connected.Entities/EntitiesExtensions.cs b/src/Connected.Entities/EntitiesExtensions.cs index fca3f4a..8be8e28 100644 --- a/src/Connected.Entities/EntitiesExtensions.cs +++ b/src/Connected.Entities/EntitiesExtensions.cs @@ -85,6 +85,14 @@ public static class EntitiesExtensions return Serializer.Merge(newEntity, existing, modifier, new StateModifier { State = state }, sources); } + public static TEntity Clone(this TEntity existing) + where TEntity : IEntity + { + var newEntity = Activator.CreateInstance(); + + return Serializer.Merge(newEntity, existing); + } + public static async Task> AsEntities(this IQueryable source, CancellationToken cancellationToken = default) { if (source is null)