using System.Reflection;

namespace Waaagh.Helpers {
    public interface IUpdateReferences<T> {
        void UpdateReferences(T value);
    }

    static internal class ModelUpdateHelper {
        static public void UpdateWritableProperies<T>(ref T source, T value) where T : IUpdateReferences<T> {
            Type type = typeof(T);
            PropertyInfo[] properties = type.GetProperties();
            foreach (PropertyInfo property in properties) {
                if (property.CanWrite) {
                    property.SetValue(source, property.GetValue(value));
                }
            }
        }
    }
}