Add version processor window
This commit is contained in:
@@ -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;
|
||||
//}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StructureHelperCommon.Infrastructures.Interfaces
|
||||
{
|
||||
/// <summary>
|
||||
/// Creates deep clone of object
|
||||
/// </summary>
|
||||
/// <typeparam name="T"></typeparam>
|
||||
public interface ICloneStrategy<T>
|
||||
{
|
||||
/// <summary>
|
||||
/// Returns deep clone of object
|
||||
/// </summary>
|
||||
/// <param name="sourceObject"></param>
|
||||
/// <returns></returns>
|
||||
T GetClone(T sourceObject);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace StructureHelperCommon.Infrastructures.Interfaces
|
||||
{
|
||||
public interface ICloningStrategy
|
||||
{
|
||||
T Clone<T>(T original, ICloneStrategy<T>? cloneStrategy = null) where T : class;
|
||||
}
|
||||
}
|
||||
@@ -16,6 +16,9 @@ namespace StructureHelperCommon.Models.Analyses
|
||||
if (ReferenceEquals(targetObject, sourceObject)) { return; }
|
||||
targetObject.Name = sourceObject.Name;
|
||||
targetObject.Tags = sourceObject.Tags;
|
||||
targetObject.Comment = sourceObject.Comment;
|
||||
targetObject.Color = sourceObject.Color;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Media;
|
||||
|
||||
namespace StructureHelperCommon.Models.Analyses
|
||||
{
|
||||
@@ -11,6 +12,8 @@ namespace StructureHelperCommon.Models.Analyses
|
||||
{
|
||||
string Name { get; set; }
|
||||
string Tags { get; set; }
|
||||
string Comment { get; set; }
|
||||
Color Color { get; set; }
|
||||
IVersionProcessor VersionProcessor { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user