Advertisement
pushrbx

Clone Object

Aug 21st, 2013
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.27 KB | None | 0 0
  1. public static T Clone<T>(this T source) where T : class
  2. {
  3.     T nobj = (T)Activator.CreateInstance(typeof(T));
  4.     var props = typeof(T).GetProperties();
  5.  
  6.     foreach (var p in props)
  7.     {
  8.         p.SetValue(nobj, p.GetValue(source));
  9.     }
  10.  
  11.     return nobj;
  12. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement