超全模态模型 × Harness 升级,升级解锁 ArkClaw,最新支持 DeepSeek-V4 系列与 GLM-5.1
直接序列化Action<object>委托存在诸多限制(如依赖目标对象可序列化、方法签名/类型稳定性要求高等),我们需要通过序列化方法元数据+目标对象的方式间接实现,以下是具体实现方案:
Action<object>
public class Event { // 原有成员变量保持不变 private TimeSpan m_Offset = TimeSpan.Zero; private TimeSpan m_Duration = TimeSpan.Zero; private TimeSpan m_Countdown = TimeSpan.Zero; private int m_OffsetFromUTC = -8; DateTime m_EventStart, m_EventEnd; private Server.Timer m_Timer; private bool m_Calledstart = false; private Item m_item; private object m_context; private Action<object> m_startedCallback; private Action<object> m_endedCallback; public Event(Item you, object context = null, Action<object> startedCallback = null, Action<object> endedCallback = null) { m_item = you; m_context = context; m_startedCallback = startedCallback; m_endedCallback = endedCallback; } public void Serialize(GenericWriter writer) { writer.Write((int)2); // 版本升级为2,新增回调序列化逻辑 writer.Write(DateTime.Now); writer.Write(m_Duration); writer.Write(m_Calledstart); writer.Write(m_OffsetFromUTC); writer.Write(m_Offset); // 序列化两个回调 SerializeAction(writer, m_startedCallback); SerializeAction(writer, m_endedCallback); } private void SerializeAction(GenericWriter writer, Action<object> action) { if (action == null) { writer.Write(false); // 标记回调为null return; } writer.Write(true); var method = action.Method; writer.Write(method.IsStatic); if (method.IsStatic) { // 静态方法:保存类型全名和方法名 writer.Write(method.DeclaringType.FullName); writer.Write(method.Name); } else { // 实例方法:保存目标对象(需可序列化)和方法名 writer.Write(action.Target); writer.Write(method.Name); } } public void Deserialize(GenericReader reader) { int version = reader.ReadInt(); switch (version) { case 2: { // 读取原有版本1的内容 DateTime temp = reader.ReadDateTime(); m_Countdown = DateTime.Now - temp; m_Duration = reader.ReadTimeSpan(); m_Calledstart = reader.ReadBool(); m_OffsetFromUTC = reader.ReadInt(); m_Offset = reader.ReadTimeSpan(); // 反序列化回调 m_startedCallback = DeserializeAction(reader); m_endedCallback = DeserializeAction(reader); break; } case 1: { DateTime temp = reader.ReadDateTime(); m_Countdown = DateTime.Now - temp; m_Duration = reader.ReadTimeSpan(); m_Calledstart = reader.ReadBool(); m_OffsetFromUTC = reader.ReadInt(); m_Offset = reader.ReadTimeSpan(); // 旧版本无回调,默认赋值null m_startedCallback = null; m_endedCallback = null; break; } } } private Action<object> DeserializeAction(GenericReader reader) { bool hasAction = reader.ReadBool(); if (!hasAction) { return null; } bool isStatic = reader.ReadBool(); if (isStatic) { string typeName = reader.ReadString(); string methodName = reader.ReadString(); Type type = Type.GetType(typeName); if (type == null) return null; // 查找匹配签名的静态方法 MethodInfo method = type.GetMethod(methodName, BindingFlags.Public | BindingFlags.Static, null, new[] { typeof(object) }, null); if (method == null) return null; return (Action<object>)Delegate.CreateDelegate(typeof(Action<object>), method); } else { object target = reader.ReadObject(); string methodName = reader.ReadString(); if (target == null) return null; Type targetType = target.GetType(); // 先找公共实例方法,找不到再尝试私有方法 MethodInfo method = targetType.GetMethod(methodName, BindingFlags.Public | BindingFlags.Instance, null, new[] { typeof(object) }, null) ?? targetType.GetMethod(methodName, BindingFlags.NonPublic | BindingFlags.Instance, null, new[] { typeof(object) }, null); if (method == null) return null; return (Action<object>)Delegate.CreateDelegate(typeof(Action<object>), target, method); } } }
Item
[Serializable]
void 方法名(object 参数)
内容的提问来源于stack exchange,提问作者Level 42
超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起
模型再升级,30秒超长叙事, 模态参考扩容
模型自由,工具不限,最新支持 Deepseek-V4 系列、GLM-5.3 系列
超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列
大模型19元起,Al应用9.9元畅享,新人首购爆款尽享优惠