summaryrefslogtreecommitdiff
path: root/Assets/ThirdParty/VRM/VRM/UniJSON/Scripts/ListTreeNode/ListTreeNodeArrayExtensions.cs
diff options
context:
space:
mode:
Diffstat (limited to 'Assets/ThirdParty/VRM/VRM/UniJSON/Scripts/ListTreeNode/ListTreeNodeArrayExtensions.cs')
-rw-r--r--Assets/ThirdParty/VRM/VRM/UniJSON/Scripts/ListTreeNode/ListTreeNodeArrayExtensions.cs59
1 files changed, 59 insertions, 0 deletions
diff --git a/Assets/ThirdParty/VRM/VRM/UniJSON/Scripts/ListTreeNode/ListTreeNodeArrayExtensions.cs b/Assets/ThirdParty/VRM/VRM/UniJSON/Scripts/ListTreeNode/ListTreeNodeArrayExtensions.cs
new file mode 100644
index 00000000..7a68d2ac
--- /dev/null
+++ b/Assets/ThirdParty/VRM/VRM/UniJSON/Scripts/ListTreeNode/ListTreeNodeArrayExtensions.cs
@@ -0,0 +1,59 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+
+
+namespace UniJSON
+{
+ public static class ListTreeNodeArrayExtensions
+ {
+ public static IEnumerable<ListTreeNode<T>> ArrayItems<T>(this ListTreeNode<T> self) where T : IListTreeItem, IValue<T>
+ {
+ if (!self.IsArray()) throw new DeserializationException("is not array");
+ return self.Children;
+ }
+
+ [Obsolete("Use GetArrayItem(index)")]
+ public static ListTreeNode<T> GetArrrayItem<T>(this ListTreeNode<T> self, int index)
+ where T : IListTreeItem, IValue<T>
+ {
+ return GetArrayItem(self, index);
+ }
+
+ public static ListTreeNode<T> GetArrayItem<T>(this ListTreeNode<T> self, int index)
+ where T : IListTreeItem, IValue<T>
+ {
+ int i = 0;
+ foreach (var v in self.ArrayItems())
+ {
+ if (i++ == index)
+ {
+ return v;
+ }
+ }
+ throw new KeyNotFoundException();
+ }
+
+ public static int GetArrayCount<T>(this ListTreeNode<T> self)
+ where T : IListTreeItem, IValue<T>
+ {
+ if (!self.IsArray()) throw new DeserializationException("is not array");
+ return self.Children.Count();
+ }
+
+ public static int IndexOf<T>(this ListTreeNode<T> self, ListTreeNode<T> child)
+ where T : IListTreeItem, IValue<T>
+ {
+ int i = 0;
+ foreach (var v in self.ArrayItems())
+ {
+ if (v.ValueIndex == child.ValueIndex)
+ {
+ return i;
+ }
+ ++i;
+ }
+ throw new KeyNotFoundException();
+ }
+ }
+}