Thursday, June 15, 2017

Cloning c# Objects in generic way

Here is the simple solution for cloning the c# objects in generic way

Use this below extension method to clone the obejcts



public static T Clone<T>(T source)
{
    var serialized = JsonConvert.SerializeObject(source);
    return JsonConvert.DeserializeObject<T>(serialized);
}

No comments:

Post a Comment