Referencing this answer to a question.
Can this be rewritten as:
private static BinaryFormatter formatter = new BinaryFormatter();
public static T DeepClone<T>(this T a)
{
using(MemoryStream stream = new MemoryStream())
{
formatter.Serialize(stream, a);
stream.Position = 0;
return (T)formatter.Deserialize(stream);
}
}
So avoiding constructing (and GC'ing) a new BinaryFormatter for each call?
This code path is getting hit very frequently as it involves our caching layer and I would like to make it as lightweight as possible.
Thanks.