Advertisement
skb50bd

F# With In C# (Kinda)

Jul 31st, 2018
240
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.66 KB | None | 0 0
  1.    static class BrotalExtensions {
  2.         public static T Copy<T>(this T original) where T : new() {
  3.             T duplicate = new T();
  4.  
  5.             original.GetType()
  6.                     .GetProperties()
  7.                     .ToList()
  8.                     .ForEach(p => p.SetValue(
  9.                         duplicate,
  10.                         p.GetValue(original)));
  11.  
  12.             return duplicate;
  13.         }
  14.  
  15.         public static T With<T>(this T original, params Action<T>[] actions) where T : new() {
  16.             T duplicate = original.Copy();
  17.  
  18.             actions.ToList().ForEach(a => a(duplicate));
  19.  
  20.             return duplicate;
  21.         }
  22.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement