//------------------------------------------------------------------------------ // 此代码版权(除特别声明或在XREF结尾的命名空间的代码)归作者本人若汝棋茗所有 // 源代码使用协议遵循本仓库的开源协议及附加协议,若本仓库没有设置,则按MIT开源协议授权 // CSDN博客:https://blog.csdn.net/qq_40374647 // 哔哩哔哩视频:https://space.bilibili.com/94253567 // Gitee源代码仓库:https://gitee.com/RRQM_Home // Github源代码仓库:https://github.com/RRQM // API首页:https://www.yuque.com/rrqm/touchsocket/index // 交流QQ群:234762506 // 感谢您的下载和使用 //------------------------------------------------------------------------------ //------------------------------------------------------------------------------ using System.Collections; using System.Collections.Concurrent; using System.Collections.Generic; using System.Linq; namespace TouchSocket.Rpc { /// /// 服务映射图 /// public class ActionMap : IEnumerable> { private readonly ConcurrentDictionary m_actionMap = new ConcurrentDictionary(); /// /// 服务键集合 /// public IEnumerable ActionKeys => m_actionMap.Keys; /// /// 添加调用 /// /// /// public void Add(string actionKey, MethodInstance methodInstance) { if (m_actionMap.ContainsKey(actionKey)) { throw new System.Exception($"调用键为{actionKey}的函数已存在。"); } m_actionMap.TryAdd(actionKey, methodInstance); } /// /// 获取所有服务函数实例 /// /// public MethodInstance[] GetAllMethodInstances() { return m_actionMap.Values.ToArray(); } /// /// 返回迭代器 /// /// public IEnumerator> GetEnumerator() { return m_actionMap.GetEnumerator(); } IEnumerator IEnumerable.GetEnumerator() { return m_actionMap.GetEnumerator(); } /// /// 通过actionKey获取函数实例 /// /// /// public MethodInstance GetMethodInstance(string actionKey) { m_actionMap.TryGetValue(actionKey, out MethodInstance methodInstance); return methodInstance; } /// /// 移除 /// /// /// public bool Remove(string actionKey, out MethodInstance methodInstance) { return m_actionMap.TryRemove(actionKey, out methodInstance); } /// /// 移除 /// /// /// public bool Remove(string actionKey) { return m_actionMap.TryRemove(actionKey, out _); } /// /// 通过actionKey获取函数实例 /// /// /// /// public bool TryGetMethodInstance(string actionKey, out MethodInstance methodInstance) { return m_actionMap.TryGetValue(actionKey, out methodInstance); } } }