PhoneToolMX/PhoneToolMX.Models/Models/IModel.cs
2023-10-17 21:55:10 -07:00

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);
}
}
}
}
}