20 lines
543 B
C#
20 lines
543 B
C#
using System.Reflection;
|
|
|
|
namespace PhoneToolMX.Models
|
|
{
|
|
public interface IModel
|
|
{
|
|
public int? Id { get; set; }
|
|
|
|
public void Commit(IModel obj)
|
|
{
|
|
if (GetType() != obj.GetType()) throw new ArgumentException("Input object must be the same model");
|
|
foreach (var prop in GetType().GetProperties().Where(p => p.CanWrite)) {
|
|
if (prop.GetValue(obj, null) is {} propVal) {
|
|
prop.SetValue(this, propVal, null);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|