|
@@ -131,7 +131,7 @@ namespace InABox.Core
|
|
|
SetObserving(true);
|
|
|
}
|
|
|
|
|
|
- private bool _disabledInterceptor;
|
|
|
+ internal bool _disabledInterceptor;
|
|
|
|
|
|
protected T InitializeField<T>(ref T? field, string name)
|
|
|
where T : BaseObject, ISubObject, new()
|
|
@@ -536,6 +536,20 @@ namespace InABox.Core
|
|
|
|
|
|
public static class BaseObjectExtensions
|
|
|
{
|
|
|
+ public static T Clone<T>(this T obj) where T : BaseObject, new()
|
|
|
+ {
|
|
|
+ var newObj = new T();
|
|
|
+ obj._disabledInterceptor = true;
|
|
|
+ foreach(var property in DatabaseSchema.Properties(obj.GetType()))
|
|
|
+ {
|
|
|
+ if (property.Parent != null && property.Parent.NullSafeGetter()(obj) is null) continue;
|
|
|
+
|
|
|
+ property.Setter()(newObj, property.Getter()(obj));
|
|
|
+ }
|
|
|
+ obj._disabledInterceptor = false;
|
|
|
+ return newObj;
|
|
|
+ }
|
|
|
+
|
|
|
public static bool HasChanged(object? before, object? after)
|
|
|
{
|
|
|
if ((before == null || before.Equals("")) && (after == null || after.Equals("")))
|