ModelUpdateHelper.cs 624 B

12345678910111213141516171819
  1. using System.Reflection;
  2. namespace Waaagh.Helpers {
  3. public interface IUpdateReferences<T> {
  4. void UpdateReferences(T value);
  5. }
  6. static internal class ModelUpdateHelper {
  7. static public void UpdateWritableProperies<T>(ref T source, T value) where T : IUpdateReferences<T> {
  8. Type type = typeof(T);
  9. PropertyInfo[] properties = type.GetProperties();
  10. foreach (PropertyInfo property in properties) {
  11. if (property.CanWrite) {
  12. property.SetValue(source, property.GetValue(value));
  13. }
  14. }
  15. }
  16. }
  17. }