mirror of
https://gitee.com/langsisi_admin/serein-flow
synced 2026-03-02 15:50:47 +08:00
2. Script脚本添加了原始字符串的实现 3. 修复了Script中无法对 \" 双引号转义的问题 4. 新增了对于集合嵌套取值的支持(目前仅是集合取值) 5. 重新设计了FlowWorkManagement任务启动的逻辑,修复了触发器无法正常运行的问题 6. 在ScriptBaseFunc中新增了 json() 本地函数,支持将字符串转为IJsonToken进行取值。 7. EmitHelper对于集合取值时,反射获取“get_item”委托时存在看你多个MethodInfo,现在可以传入子项类型,帮助匹配目标重载方法
122 lines
3.6 KiB
C#
122 lines
3.6 KiB
C#
using Newtonsoft.Json.Linq;
|
|
using Serein.Library.Api;
|
|
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace Serein.Extend.NewtonsoftJson
|
|
{
|
|
public sealed class NewtonsoftJsonArrayToken : IJsonToken, IList<IJsonToken>
|
|
{
|
|
private readonly JArray _array;
|
|
public NewtonsoftJsonArrayToken(JArray array) => _array = array;
|
|
|
|
public bool IsNull => false;
|
|
public bool IsObject => false;
|
|
public bool IsArray => true;
|
|
|
|
public int Count => _array.Count;
|
|
|
|
public bool IsReadOnly => _array.IsReadOnly;
|
|
|
|
|
|
public string GetString() => _array.ToString();
|
|
public int GetInt32() => throw new InvalidOperationException("不是值类型");
|
|
public bool GetBoolean() => throw new InvalidOperationException("不是值类型");
|
|
|
|
public IJsonToken this[object key] => key is int index ? this[index] : throw new InvalidOperationException("不是对象类型");
|
|
|
|
public IJsonToken this[int index]
|
|
{
|
|
get => NewtonsoftJsonTokenFactory.FromJToken(_array[index]);
|
|
set => _array[index] = JToken.FromObject(value.ToObject<object>());
|
|
}
|
|
|
|
|
|
public IEnumerable<IJsonToken> EnumerateArray()
|
|
{
|
|
foreach (var t in _array)
|
|
yield return NewtonsoftJsonTokenFactory.FromJToken(t);
|
|
}
|
|
|
|
public T ToObject<T>() => throw new InvalidOperationException("不是对象类型");
|
|
public object ToObject(Type type) => throw new InvalidOperationException("不是对象类型");
|
|
public override string ToString() => _array.ToString();
|
|
|
|
public bool TryGetValue(string name, out IJsonToken token) => throw new InvalidOperationException("不是对象类型");
|
|
public IJsonToken? GetValue(string name) => throw new InvalidOperationException("不是对象类型");
|
|
|
|
public int IndexOf(IJsonToken item)
|
|
{
|
|
var jt = JToken.FromObject(item.ToObject<object>());
|
|
for (int i = 0; i < _array.Count; i++)
|
|
{
|
|
if (JToken.DeepEquals(_array[i], jt))
|
|
return i;
|
|
}
|
|
return -1;
|
|
}
|
|
|
|
|
|
public void Insert(int index, IJsonToken item)
|
|
{
|
|
_array.Insert(index, JToken.FromObject(item.ToObject<object>()));
|
|
}
|
|
|
|
public void RemoveAt(int index)
|
|
{
|
|
_array.RemoveAt(index);
|
|
}
|
|
|
|
public void Add(IJsonToken item)
|
|
{
|
|
_array.Add(JToken.FromObject(item.ToObject<object>()));
|
|
}
|
|
|
|
public void Clear()
|
|
{
|
|
_array.Clear();
|
|
}
|
|
|
|
public bool Contains(IJsonToken item)
|
|
{
|
|
var jt = JToken.FromObject(item.ToObject<object>());
|
|
return _array.Any(x => JToken.DeepEquals(x, jt));
|
|
}
|
|
|
|
public void CopyTo(IJsonToken[] array, int arrayIndex)
|
|
{
|
|
foreach (var item in _array)
|
|
{
|
|
array[arrayIndex++] = NewtonsoftJsonTokenFactory.FromJToken(item);
|
|
}
|
|
}
|
|
|
|
public bool Remove(IJsonToken item)
|
|
{
|
|
int index = IndexOf(item);
|
|
if (index >= 0)
|
|
{
|
|
_array.RemoveAt(index);
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
public IEnumerator<IJsonToken> GetEnumerator()
|
|
{
|
|
foreach (var item in _array)
|
|
yield return NewtonsoftJsonTokenFactory.FromJToken(item);
|
|
}
|
|
|
|
IEnumerator IEnumerable.GetEnumerator()
|
|
{
|
|
return GetEnumerator();
|
|
}
|
|
|
|
}
|
|
}
|