I am trying to clone an object in a way that i get a fresh copy of existing instance.
I am using AutoMapper like this:
Mapper.CreateMap(typeof(VariableSet), typeof(VariableSet));
var destinationObject = Mapper.Map<VariableSet>(command.VariableSets[0]);
command.VariableSets.Add(destinationObject);
I have an array:
command.VariableSets
I am trying to add another instance of the object that is at 0th index of this array. but when i use auto mapper it creates another instance by reference. So if i change any sub property in 0th index object, it also gets updated in 1st index object.
i tried cloning the object using serialization deserialization method but than i have to make my objects [Serializable]
which has its own issue.