Beispiel #1
0
 public static T DeepClone <T>(this IEntityDaBase entity)
     where T : IEntityDaBase
 {
     try
     {
         if (entity is T castedObject)
         {
             using (MemoryStream memoryStream = new MemoryStream())
             {
                 BinaryFormatter formatter = new BinaryFormatter();
                 formatter.Serialize(memoryStream, castedObject);
                 memoryStream.Position = 0;
                 return((T)formatter.Deserialize(memoryStream));
             }
         }
         return(default(T));
     }
     catch
     {
         return(default(T));
     }
 }
 private static void AddToDbContextSet(PetShopDBContext datacontxt, IEntityDaBase item)
 {
     //Type type = item.GetType();
     datacontxt.Set(item.GetType()).Add(item);
 }