Skip to content

Commit

Permalink
Improved empty collections and fields handling in extras structures. F…
Browse files Browse the repository at this point in the history
…ixes #105
  • Loading branch information
vpenades committed Sep 28, 2021
1 parent 326bdb5 commit 714c4bf
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/SharpGLTF.Core/IO/JsonContent.Impl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,8 @@ private static Array TryClone(IEnumerable collection)
}
}

if (count == 0) { return Array.Empty<Object>(); }

if (elementType.IsGenericType && elementType.GetGenericTypeDefinition() == typeof(IReadOnlyDictionary<,>))
{
elementType = typeof(IDictionary);
Expand Down Expand Up @@ -491,6 +493,7 @@ private static IEnumerable<JSONPROPERTY> _Enumerate(IDictionary dict)
{
foreach (DictionaryEntry entry in dict)
{
if (entry.Value == null) continue;
yield return new JSONPROPERTY(_GetKey(entry.Key), _GetValue(entry.Value));
}
}
Expand All @@ -499,6 +502,7 @@ private static IEnumerable<JSONPROPERTY> _Enumerate<TKey, TValue>(IEnumerable<Ke
{
foreach (var entry in dict)
{
if (entry.Value == null) continue;
yield return new JSONPROPERTY(_GetKey(entry.Key), _GetValue(entry.Value));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,11 @@ public void CreateSceneWithExtras()
var dict = new Dictionary<string, object>();

dict["author"] = "me";
dict["string_null"] = (string)null;

dict["value1"] = 17;
dict["array1"] = new List<int> { 1, 2, 3 };
dict["array_empty"] = new List<int>();
dict["dict1"] = new Dictionary<string, object>
{
["A"] = 16,
Expand Down

0 comments on commit 714c4bf

Please sign in to comment.