I am using this method to make a deep copy of a List of objects:
public static List<TransformColumn> Clone(List<TransformColumn> original)
{
List<TransformColumn> returnValue;
using (var stream = new System.IO.MemoryStream())
{
var binaryFormatter = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter();
binaryFormatter.Serialize(stream, original); //serialize to stream
stream.Position = 0;
//deserialize from stream.
returnValue = binaryFormatter.Deserialize(stream) as List<TransformColumn>;
}
return returnValue;
}
My question is how do I change this method to accept a List of any type and retyurn the clone of that list?
Also, what would usage look like of your answer please!
You can make your method even more generic by allowing any type not only
List<>, see my answer for the same question with a set of unit tests, error handling, also it is implemented as extension method so easy to use. See This StackOverflow postSignature of method is:
Ans obviously you can create more simple overload without
throwInCaseOfErrorparameter: