mirror of
https://github.com/vrm-c/UniVRM.git
synced 2026-09-07 11:28:35 -05:00
MsgPack と Json を共用にするための Generics ListTreeNode を 単純な型 JsonNode で置き換え
This commit is contained in:
@@ -7,8 +7,7 @@ namespace UniJSON
|
||||
{
|
||||
public static class IValueNodeObjectExtensions
|
||||
{
|
||||
public static IEnumerable<KeyValuePair<ListTreeNode<T>, ListTreeNode<T>>> ObjectItems<T>(this ListTreeNode<T> self)
|
||||
where T : IListTreeItem, IValue<T>
|
||||
public static IEnumerable<KeyValuePair<JsonNode, JsonNode>> ObjectItems(this JsonNode self)
|
||||
{
|
||||
if (!self.IsMap()) throw new DeserializationException("is not object");
|
||||
var it = self.Children.GetEnumerator();
|
||||
@@ -17,19 +16,17 @@ namespace UniJSON
|
||||
var key = it.Current;
|
||||
|
||||
it.MoveNext();
|
||||
yield return new KeyValuePair<ListTreeNode<T>, ListTreeNode<T>>(key, it.Current);
|
||||
yield return new KeyValuePair<JsonNode, JsonNode>(key, it.Current);
|
||||
}
|
||||
}
|
||||
|
||||
public static int GetObjectCount<T>(this ListTreeNode<T> self)
|
||||
where T : IListTreeItem, IValue<T>
|
||||
public static int GetObjectCount(this JsonNode self)
|
||||
{
|
||||
if (!self.IsMap()) throw new DeserializationException("is not object");
|
||||
return self.Children.Count() / 2;
|
||||
}
|
||||
|
||||
public static string GetObjectValueOrDefault<T>(this ListTreeNode<T> self, String key, string defualtValue)
|
||||
where T : IListTreeItem, IValue<T>
|
||||
public static string GetObjectValueOrDefault(this JsonNode self, String key, string defualtValue)
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -41,15 +38,12 @@ namespace UniJSON
|
||||
}
|
||||
}
|
||||
|
||||
public static ListTreeNode<T> GetObjectItem<T>(this ListTreeNode<T> self, String key)
|
||||
where T : IListTreeItem, IValue<T>
|
||||
public static JsonNode GetObjectItem(this JsonNode self, String key)
|
||||
{
|
||||
return self.GetObjectItem(Utf8String.From(key));
|
||||
}
|
||||
|
||||
public static ListTreeNode<T> GetObjectItem<T>(this ListTreeNode<T> self, Utf8String key)
|
||||
where T : IListTreeItem, IValue<T>
|
||||
|
||||
public static JsonNode GetObjectItem(this JsonNode self, Utf8String key)
|
||||
{
|
||||
foreach (var kv in self.ObjectItems())
|
||||
{
|
||||
@@ -61,21 +55,18 @@ namespace UniJSON
|
||||
throw new KeyNotFoundException();
|
||||
}
|
||||
|
||||
public static bool ContainsKey<T>(this ListTreeNode<T> self, Utf8String key)
|
||||
where T : IListTreeItem, IValue<T>
|
||||
public static bool ContainsKey(this JsonNode self, Utf8String key)
|
||||
{
|
||||
return self.ObjectItems().Any(x => x.Key.GetUtf8String() == key);
|
||||
}
|
||||
|
||||
public static bool ContainsKey<T>(this ListTreeNode<T> self, String key)
|
||||
where T : IListTreeItem, IValue<T>
|
||||
public static bool ContainsKey(this JsonNode self, String key)
|
||||
{
|
||||
var ukey = Utf8String.From(key);
|
||||
return self.ContainsKey(ukey);
|
||||
}
|
||||
|
||||
public static Utf8String KeyOf<T>(this ListTreeNode<T> self, ListTreeNode<T> node)
|
||||
where T : IListTreeItem, IValue<T>
|
||||
public static Utf8String KeyOf(this JsonNode self, JsonNode node)
|
||||
{
|
||||
foreach (var kv in self.ObjectItems())
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user