Add version processor window

This commit is contained in:
Evgeny Redikultsev
2024-11-23 20:42:21 +05:00
parent 6ec68c6f49
commit 32243f5448
50 changed files with 1018 additions and 158 deletions

View File

@@ -0,0 +1,60 @@
using StructureHelperCommon.Infrastructures.Exceptions;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
namespace StructureHelperCommon.Infrastructures.Interfaces
{
public class DeepCloningStrategy : ICloningStrategy
{
private readonly Dictionary<object, object> _clonedObjects = new Dictionary<object, object>();
public T Clone<T>(T original, ICloneStrategy<T>? cloneStrategy = null) where T : class
{
if (original == null) return null;
// Check if the object is already cloned
if (_clonedObjects.TryGetValue(original, out var existingClone))
return (T)existingClone;
// Perform custom cloning logic based on the object's type
T clone;
if (cloneStrategy is not null)
{
clone = cloneStrategy.GetClone(original);
}
// Check if the object implements ICloneable (or IClone) and use that method
else if (original is ICloneable cloneable)
{
clone = cloneable.Clone() as T; // Use the ICloneable interface's Clone method
}
else
{
throw new StructureHelperException(ErrorStrings.DataIsInCorrect + ": object is not IClonable and cloning strategy is null");
}
_clonedObjects[original] = clone;
return clone;
}
//private T CreateClone<T>(T original) where T : class
//{
// // Example logic for creating a clone (modify as needed for your use case)
// var type = original.GetType();
// var clone = Activator.CreateInstance(type);
// foreach (var field in type.GetFields(BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance))
// {
// var value = field.GetValue(original);
// field.SetValue(clone, Clone(value));
// }
// return (T)clone;
//}
}
}