pushrbx icon

Clone Object

pushrbx | PRO | 08/21/13 06:50:04 AM UTC | 0 ⭐ | 390 👁️ | Never ⏰ | []
C# |

270 B

|

None

|

0 👍

/

0 👎

public static T Clone<T>(this T source) where T : class
{
    T nobj = (T)Activator.CreateInstance(typeof(T));
    var props = typeof(T).GetProperties();
 
    foreach (var p in props)
    {
        p.SetValue(nobj, p.GetValue(source));
    }
 
    return nobj;
}

Comments