diff --git a/src/SharpGLTF.Cesium/BinaryTable.cs b/src/SharpGLTF.Cesium/Memory/BinaryTable.cs similarity index 95% rename from src/SharpGLTF.Cesium/BinaryTable.cs rename to src/SharpGLTF.Cesium/Memory/BinaryTable.cs index 259e7b8e..a8795b02 100644 --- a/src/SharpGLTF.Cesium/BinaryTable.cs +++ b/src/SharpGLTF.Cesium/Memory/BinaryTable.cs @@ -6,7 +6,7 @@ using System.Runtime.InteropServices; using System.Text; -namespace SharpGLTF +namespace SharpGLTF.Memory { /// /// Function for converting data into binary buffers @@ -54,7 +54,7 @@ public static byte[] GetBytes(IReadOnlyList values) { return Vector4ToBytes(values); } - else if(typeof(T) == typeof(Matrix4x4)) + else if (typeof(T) == typeof(Matrix4x4)) { return Matrix4x4ToBytes(values); } @@ -166,14 +166,14 @@ public static List GetStringOffsets(List values) public static List GetStringOffsets(List> values) { - var offsets = new List() {}; + var offsets = new List() { }; foreach (var arr in values) { var arrOffsets = GetStringOffsets(arr); var last = offsets.LastOrDefault(); foreach (var offset in arrOffsets) { - if(!offsets.Contains(last + offset)) + if (!offsets.Contains(last + offset)) { offsets.Add(last + offset); } @@ -197,12 +197,12 @@ public static List GetArrayOffsets(List> values) public static int GetSize() { - #if NETSTANDARD2_0 +#if NETSTANDARD2_0 var isValueType = typeof(T).IsValueType; - #else - var isValueType = !System.Runtime.CompilerServices.RuntimeHelpers.IsReferenceOrContainsReferences(); - #endif - +#else + var isValueType = !System.Runtime.CompilerServices.RuntimeHelpers.IsReferenceOrContainsReferences(); +#endif + Guard.IsTrue(isValueType, nameof(T), "T must be a value type"); var type = typeof(T); diff --git a/src/SharpGLTF.Cesium/Schema2/Ext.StructuralMetadataRoot.cs b/src/SharpGLTF.Cesium/Schema2/Ext.StructuralMetadataRoot.cs index 238544c5..af298deb 100644 --- a/src/SharpGLTF.Cesium/Schema2/Ext.StructuralMetadataRoot.cs +++ b/src/SharpGLTF.Cesium/Schema2/Ext.StructuralMetadataRoot.cs @@ -1,4 +1,5 @@ using OneOf; +using SharpGLTF.Memory; using SharpGLTF.Validation; using System; using System.Collections.Generic; diff --git a/tests/SharpGLTF.Cesium.Tests/BinaryTableTests.cs b/tests/SharpGLTF.Cesium.Tests/Memory/BinaryTableTests.cs similarity index 91% rename from tests/SharpGLTF.Cesium.Tests/BinaryTableTests.cs rename to tests/SharpGLTF.Cesium.Tests/Memory/BinaryTableTests.cs index 845bcf93..e18b99d5 100644 --- a/tests/SharpGLTF.Cesium.Tests/BinaryTableTests.cs +++ b/tests/SharpGLTF.Cesium.Tests/Memory/BinaryTableTests.cs @@ -3,7 +3,7 @@ using System.Collections.Generic; using System.Globalization; -namespace SharpGLTF +namespace SharpGLTF.Memory { public class BinaryTableTests { @@ -66,9 +66,9 @@ public void ConvertMatrix4x4ToBytes() public void TestGetArrayOffset() { // arrange - var list0 = new List(){ "hello", "world!"}; - var list1 = new List(){"test", "testtest"}; - var arrays = new List>() { list0, list1 }; + var list0 = new List() { "hello", "world!" }; + var list1 = new List() { "test", "testtest" }; + var arrays = new List>() { list0, list1 }; // act var arrayOffsets = BinaryTable.GetArrayOffsets(arrays); @@ -81,7 +81,7 @@ public void TestGetArrayOffset() var l1 = list1.Count; Assert.That(arrayOffsets[1], Is.EqualTo(l0)); - Assert.That(arrayOffsets[2], Is.EqualTo(l0+l1)); + Assert.That(arrayOffsets[2], Is.EqualTo(l0 + l1)); Assert.That(stringOffsets.Count, Is.EqualTo(list0.Count + list1.Count + 1)); Assert.That(stringOffsets[0], Is.EqualTo(0)); @@ -99,13 +99,13 @@ public void TestBinaryConversion() bytes = BinaryTable.GetBytes(GetTestArray()); Assert.That(bytes.Length, Is.EqualTo(BinaryTable.GetSize() * 2)); - + bytes = BinaryTable.GetBytes(new List() { "a", "b" }); Assert.That(bytes.Length, Is.EqualTo(2)); - bytes = BinaryTable.GetBytes(new List() { true, false }); + bytes = BinaryTable.GetBytes(new List() { true, false }); Assert.That(bytes.Length, Is.EqualTo(1)); - + var bits = new System.Collections.BitArray(bytes); Assert.That(bits[0] == true); Assert.That(bits[1] == false); @@ -119,7 +119,7 @@ public void TestBinaryConversion() private static List GetTestArray() { var l = new List(); - l.Add((T)Convert.ChangeType(0, typeof(T),CultureInfo.InvariantCulture)); + l.Add((T)Convert.ChangeType(0, typeof(T), CultureInfo.InvariantCulture)); l.Add((T)Convert.ChangeType(1, typeof(T), CultureInfo.InvariantCulture)); return l; }