DeepCloner
DeepCloner copied to clipboard
Ability to ignore Events or Properties
Hello, I have quite a few classes that implement INotifyPropertyChanged due to mvvm, cloning these classes seems to lead to a memory error and crash problem.
Is there a way to not clone events or specific properties?
Currently, there is no such ability. I've received another similar issues and will try to implement related feature.
Has this been implemented yet? This is a great library but this causes problems if a object implements INotifyPropertyChanged.
Maybe you can hard code it to not clone that property for the time being.
Not implemented yet. Sorry, I have no time to do this in nearest time. It not simple because code tries to clone object itself in one step (if possible), for this case I need some more analyzing to find best way to copy and test it. Also, before implementing I should check, whereas real problem exists. I'll to to implement this asap, but cannot give any estimations about time. Sorry
Same issue here... When using INotifyPropertyChanged it becomes a problem that it copies the events. I was using MemberwiseClone before and had the same issue... Hoping for this to be configurable anytime soon. Thanks!
Any hacks? How to override behavior?
I have ideas, but do not have enough time to fix it. You can try to do something like
var assembly = Assembly.GetAssembly(typeof(DeepClonerExtensions));
var deepClonerSafeTypes = assembly.GetType("Force.DeepCloner.Helpers.DeepClonerSafeTypes");
var knownTypesField = deepClonerSafeTypes.GetField("KnownTypes", BindingFlags.Static | BindingFlags.NonPublic);
var knownTypes = (ConcurrentDictionary<Type, bool>)knownTypesField.GetValue(null);
knownTypes.TryAdd(typeof(type_to_ignore), true);
It's dirty hack, and it will not work in future versions, but I'll try to do something with this feature in future versions :)
Any progress?
A feasible method may be to add a generic overload to DeepClone DeepClone<T>(params Expression<T,TFieldName>[] ignoreExps) or DeepClone<T>(params string[] ignoreExps) Get the field names, attribute names, etc. that need to be ignored through ignoreExp.