Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- static class BrotalExtensions {
- public static T Copy<T>(this T original) where T : new() {
- T duplicate = new T();
- original.GetType()
- .GetProperties()
- .ToList()
- .ForEach(p => p.SetValue(
- duplicate,
- p.GetValue(original)));
- return duplicate;
- }
- public static T With<T>(this T original, params Action<T>[] actions) where T : new() {
- T duplicate = original.Copy();
- actions.ToList().ForEach(a => a(duplicate));
- return duplicate;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement