Pārlūkot izejas kodu

Fixing errors with orphan SubObjects.

Kenric Nugteren 9 mēneši atpakaļ
vecāks
revīzija
d4edfac72c
2 mainītis faili ar 15 papildinājumiem un 14 dzēšanām
  1. 4 4
      InABox.Core/EntityLink.cs
  2. 11 10
      InABox.Core/LinkedProperties.cs

+ 4 - 4
InABox.Core/EntityLink.cs

@@ -28,9 +28,9 @@ namespace InABox.Core
         [DoNotSerialize]
         protected BaseObject? LinkedEntity() => _linkedentity?.Invoke();*/
 
-        private BaseObject _linkedParent;
+        private BaseObject? _linkedParent;
 
-        private string _linkedPath;
+        private string? _linkedPath;
 
         public void SetLinkedParent(BaseObject parent)
         {
@@ -42,9 +42,9 @@ namespace InABox.Core
             _linkedPath = path;
         }
 
-        public BaseObject GetLinkedParent() => _linkedParent;
+        public BaseObject? GetLinkedParent() => _linkedParent;
 
-        public string GetLinkedPath() => _linkedPath;
+        public string? GetLinkedPath() => _linkedPath;
 
         protected override IOriginalValues CreateOriginalValues()
         {

+ 11 - 10
InABox.Core/LinkedProperties.cs

@@ -9,11 +9,11 @@ namespace InABox.Core
 {
     public interface ISubObject
     {
-        BaseObject GetLinkedParent();
+        BaseObject? GetLinkedParent();
 
         void SetLinkedParent(BaseObject obj);
 
-        string GetLinkedPath();
+        string? GetLinkedPath();
 
         void SetLinkedPath(string path);
     }
@@ -27,7 +27,7 @@ namespace InABox.Core
         {
             get
             {
-                _rootDictionary ??= LinkedProperties.GetParent(Object).OriginalValueList;
+                _rootDictionary ??= (LinkedProperties.GetParent(Object)?.OriginalValueList ?? new OriginalValues());
                 return _rootDictionary;
             }
         }
@@ -106,7 +106,7 @@ namespace InABox.Core
         {
             get
             {
-                _rootSet ??= LinkedProperties.GetParent(Object).LoadedColumns;
+                _rootSet ??= (LinkedProperties.GetParent(Object)?.LoadedColumns ?? new LoadedColumns());
                 return _rootSet;
             }
         }
@@ -178,7 +178,7 @@ namespace InABox.Core
             return filtered;
         }*/
 
-        public static BaseObject GetParent(ISubObject link)
+        public static BaseObject? GetParent(ISubObject link)
         {
             while (true)
             {
@@ -187,14 +187,14 @@ namespace InABox.Core
                 {
                     link = parentLink;
                 }
-                else
+                else 
                 {
                     return parent;
                 }
             }
         }
 
-        public static string GetPath(ISubObject link)
+        public static string? GetPath(ISubObject link)
         {
             var path = link.GetLinkedPath();
             while (true)
@@ -224,7 +224,7 @@ namespace InABox.Core
         public static IEnumerable<ILinkedProperty> Find(ISubObject subObject, out BaseObject parent)
         {
             parent = GetParent(subObject);
-            if (!_LinkedProperties.TryGetValue(parent.GetType(), out var props))
+            if (parent is null || !_LinkedProperties.TryGetValue(parent.GetType(), out var props))
             {
                 return Enumerable.Empty<ILinkedProperty>();
             }
@@ -233,12 +233,13 @@ namespace InABox.Core
             return props.Where(x => x.Path == path);
         }
 
-        public static bool Find(ISubObject subObject, string name, [NotNullWhen(true)] out ILinkedProperty? property, out BaseObject parent)
+        public static bool Find(ISubObject subObject, string name, [NotNullWhen(true)] out ILinkedProperty? property, [NotNullWhen(true)] out BaseObject? parent)
         {
             property = null;
             parent = GetParent(subObject);
-            if (parent == null)
+            if (parent is null)
                 return false;
+
             if(!_LinkedProperties.TryGetValue(parent.GetType(), out var props))
                 return false;
             var path = GetPath(subObject);