Browse Source

some collections made public to help extensions to be developed on separeted projects

vpenades 2 years ago
parent
commit
fb293314f5

+ 50 - 0
src/SharpGLTF.Core/Collections/ChildSetter.cs

@@ -0,0 +1,50 @@
+using System;
+using System.Collections.Generic;
+using System.Text;
+
+namespace SharpGLTF.Collections
+{
+    /// <summary>
+    /// Helper used to handle property assignment with bidirectional referencing
+    /// </summary>
+    /// <typeparam name="T"></typeparam>
+    /// <typeparam name="TParent"></typeparam>
+    public readonly struct ChildSetter<TParent>        
+        where TParent : class
+    {
+        #region lifecycle
+
+        public ChildSetter(TParent parent)
+        {
+            Guard.NotNull(parent, nameof(parent));
+            _Parent = parent;
+        }
+
+        #endregion
+
+        #region data
+
+        [System.Diagnostics.DebuggerBrowsable(System.Diagnostics.DebuggerBrowsableState.Never)]
+        private readonly TParent _Parent;
+
+        #endregion
+
+        #region API        
+
+        public void SetProperty<T>(ref T target, T value)
+            where T : class, IChildOfList<TParent>
+        {
+            if (value == target) return;
+
+            // orphan the current child
+            target?.SetLogicalParent(null, -1);
+            target = null;
+
+            // adopt the new child
+            target = value;
+            target?.SetLogicalParent(_Parent, 0);
+        }
+
+        #endregion
+    }
+}

+ 1 - 1
src/SharpGLTF.Core/Collections/ChildrenList.cs

@@ -13,7 +13,7 @@ namespace SharpGLTF.Collections
     /// <typeparam name="T"></typeparam>
     /// <typeparam name="TParent"></typeparam>
     [System.Diagnostics.DebuggerDisplay("{Count}")]
-    sealed class ChildrenList<T, TParent> : IList<T>, IReadOnlyList<T>
+    public sealed class ChildrenList<T, TParent> : IList<T>, IReadOnlyList<T>
         where T : class, IChildOfList<TParent>
         where TParent : class
     {

+ 1 - 1
src/SharpGLTF.Core/Collections/IChildOfList.cs

@@ -8,7 +8,7 @@ namespace SharpGLTF.Collections
     /// Implemented by children of <see cref="ChildrenList{T, TParent}"/>
     /// </summary>
     /// <typeparam name="TParent">The type of the parent class containing the collection.</typeparam>
-    interface IChildOfList<TParent>
+    public interface IChildOfList<TParent>
         where TParent : class
     {
         /// <summary>

+ 2 - 2
src/SharpGLTF.Core/Collections/LinqDictionary.cs

@@ -12,7 +12,7 @@ namespace SharpGLTF.Collections
     /// <typeparam name="TKey">The dictionary key type.</typeparam>
     /// <typeparam name="TValueIn">The internal value type.</typeparam>
     /// <typeparam name="TValueOut">The exposed value type.</typeparam>
-    readonly struct ReadOnlyLinqDictionary<TKey, TValueIn, TValueOut> : IReadOnlyDictionary<TKey, TValueOut>
+    public readonly struct ReadOnlyLinqDictionary<TKey, TValueIn, TValueOut> : IReadOnlyDictionary<TKey, TValueOut>
     {
         #region lifecycle
 
@@ -81,7 +81,7 @@ namespace SharpGLTF.Collections
         #endregion
     }
 
-    readonly struct LinqDictionary<TKey, TValueIn, TValueOut> : IDictionary<TKey, TValueOut>
+    public readonly struct LinqDictionary<TKey, TValueIn, TValueOut> : IDictionary<TKey, TValueOut>
     {
         #region lifecycle
 

+ 0 - 55
src/SharpGLTF.Core/Collections/SingleChild.cs

@@ -1,55 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Text;
-
-namespace SharpGLTF.Collections
-{
-    sealed class SingleChild<T, TParent>
-        where T : class, IChildOfList<TParent>
-        where TParent : class
-    {
-        #region lifecycle
-
-        public SingleChild(TParent parent)
-        {
-            Guard.NotNull(parent, nameof(parent));
-            _Parent = parent;
-        }
-
-        #endregion
-
-        #region data
-
-        [System.Diagnostics.DebuggerBrowsable(System.Diagnostics.DebuggerBrowsableState.Never)]
-        private readonly TParent _Parent;
-
-        [System.Diagnostics.DebuggerBrowsable(System.Diagnostics.DebuggerBrowsableState.Never)]
-        private T _Child;
-
-        #endregion
-
-        #region properties
-
-        public T Value
-        {
-            get => this._Child;
-            set
-            {
-                if (this.Value == this._Child)
-                {
-                    return;
-                }
-
-                // orphan the current child
-                if (this._Child != null) { this._Child.SetLogicalParent(null, -1); }
-                this._Child = null;
-
-                // adopt the new child
-                this._Child = value;
-                if (this._Child != null) { this._Child.SetLogicalParent(_Parent, 0); }
-            }
-        }
-
-        #endregion
-    }
-}