One of the reasons why your ResultList class will not work with Jon Skeet is because it does not implement the ICloneable interface.
Implement ICloneable for all classes you need to clone, e.g.
public class ResultItem : ICloneable { public object Clone() { var item = new ResultItem { ID = ID, Name = Name, isLegit = isLegit }; return item; } }
And also in ResultList:
public class ResultList<T> : IEnumerable<T>, ICloneable where T : ICloneable { public List<T> Results { get; set; } public decimal CenterLatitude { get; set; } public decimal CenterLongitude { get; set; } public object Clone() { var list = new ResultList<T> { CenterLatitude = CenterLatitude, CenterLongitude = CenterLongitude, Results = Results.Select(x => x.Clone()).Cast<T>().ToList() }; return list; } }
Then make a deep copy of your object:
resultList.clone();
source share