Преглед на файлове

Improvements to EntityLink.Clear()

Kenric Nugteren преди 11 месеца
родител
ревизия
26537bfddd
променени са 1 файла, в които са добавени 10 реда и са изтрити 8 реда
  1. 10 8
      InABox.Core/EntityLink.cs

+ 10 - 8
InABox.Core/EntityLink.cs

@@ -87,7 +87,6 @@ namespace InABox.Core
         public virtual bool Synchronise(object Entity)
         {
             var result = false;
-            var props = CoreUtils.PropertyList(GetType(), x => (!x.Name.Equals("ID") || Entity == null) && !x.DeclaringType.Equals(typeof(BaseObject)), false);
             foreach (var prop in DatabaseSchema.Properties(GetType()))
             {
                 if (prop.Name == "ID" || !(prop is StandardProperty stdProp) || stdProp.Property.DeclaringType.Equals(typeof(BaseObject))) continue;
@@ -112,17 +111,20 @@ namespace InABox.Core
         {
             var result = false;
             var props = CoreUtils.PropertyList(GetType(), x => !x.Name.Equals("ID"), false);
-            foreach (var key in props.Keys)
+
+            foreach (var prop in DatabaseSchema.Properties(GetType()))
             {
-                var prop = CoreUtils.GetProperty(typeof(T), key);
-                if (prop != null && prop.PropertyType.Equals(props[key]))
+                if (prop.Name == "ID" || !(prop is StandardProperty stdProp) || stdProp.Property.DeclaringType.Equals(typeof(BaseObject))) continue;
+
+                var entityProp = DatabaseSchema.Property(typeof(T), prop.Name);
+                if(entityProp != null && entityProp.PropertyType == stdProp.PropertyType)
                 {
-                    var oldvalue = CoreUtils.GetPropertyValue(this, key);
-                    var newvalue = prop.PropertyType.Equals(typeof(string)) ? "" : Activator.CreateInstance(prop.PropertyType);
-                    if ((oldvalue == null && newvalue != null) || (oldvalue != null && !oldvalue.Equals(newvalue)))
+                    var oldValue = prop.Getter()(this);
+                    var newValue = CoreUtils.GetDefault(prop.PropertyType);
+                    if(!object.Equals(oldValue, newValue))
                     {
                         result = true;
-                        CoreUtils.SetPropertyValue(this, key, newvalue);
+                        prop.Setter()(this, newValue);
                     }
                 }
             }