The next generation of the Teknik Services. Written in ASP.NET. https://www.teknik.io/
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ObjectHelper.cs 836B

1234567891011121314151617181920212223242526
  1. using System.Collections.Generic;
  2. using System.Dynamic;
  3. namespace Teknik.Utilities
  4. {
  5. public static class ObjectHelper
  6. {
  7. public static dynamic Merge(object item1, object item2)
  8. {
  9. if (item1 == null || item2 == null)
  10. return item1 ?? item2 ?? new ExpandoObject();
  11. dynamic expando = new ExpandoObject();
  12. var result = expando as IDictionary<string, object>;
  13. foreach (System.Reflection.PropertyInfo fi in item1.GetType().GetProperties())
  14. {
  15. result[fi.Name] = fi.GetValue(item1, null);
  16. }
  17. foreach (System.Reflection.PropertyInfo fi in item2.GetType().GetProperties())
  18. {
  19. result[fi.Name] = fi.GetValue(item2, null);
  20. }
  21. return result;
  22. }
  23. }
  24. }