I have a class which contains:
[DataContract(Namespace = "Default")]
public class Book
{
...
some values
...
[DataMember]
public IList<Option> BookOptions {get; set;}
...
some values
...
}
On some point in my programm, I need make a copy of existing book in database and make changes in it.
What am I doing:
var copy = (T)Activator.CreateInstance(typeof(T));
AutoMapper.Mapper.Map<T, T>(existBook, copy);
previousBook = copy;
AutoMapper.Mapper.Map(source, existBook, source.GetType(), typeof(T));
source - there are changes for book. Basically, I want to store in previousBook old data and in existBook get new one. Everything are working EXCEPT one thing: Any change in BookOptions for existBook, automatically change BookOptions in previousBook. In other words, previousBook and existBook has the same BookOptions IList... As I understand there exist reference or something similar (I''m a newbie so I can't say it more clearly).
So there is my question: How can I make a object copy without any references?