示例#1
0
            internal void Add(MulticastDelegate handler, Action <TSender, TArgs> castedHandler)
            {
                if (handler is null)
                {
                    throw new ArgumentNullException(nameof(handler));
                }

                if (Target != null && Target != handler.Target)
                {
                    throw new ArgumentException("如果代码没有写错,不可能在这里传入不一致的 Target。", nameof(handler));
                }

                Target = handler.Target;

                if (MethodHandlers.TryGetValue(handler.Method, out var handlers))
                {
                    handlers.Add(castedHandler);
                }
                else
                {
                    handlers = new List <Action <TSender, TArgs> >
                    {
                        castedHandler,
                    };
                    MethodHandlers[handler.Method] = handlers;
                }
            }
示例#2
0
        internal ThriftClientMetadata(
            Type clientType,
            String clientName,
            ThriftCodecManager codecManager)
        {
            Guard.ArgumentNotNull(clientType, nameof(clientType));
            Guard.ArgumentNotNull(codecManager, nameof(codecManager));
            Guard.ArgumentNullOrWhiteSpaceString(clientName, nameof(clientName));

            this.ClientName       = clientName;
            thriftServiceMetadata = new ThriftServiceMetadata(clientType, codecManager.Catalog);
            this.ClientType       = thriftServiceMetadata.Name;

            this.MethodHandlers = new Dictionary <MethodInfo, ThriftMethodHandler>();
            foreach (ThriftMethodMetadata methodMetadata in thriftServiceMetadata.Methods.Values)
            {
                ThriftMethodHandler methodHandler = new ThriftMethodHandler(methodMetadata, codecManager);
                MethodHandlers.Add(methodMetadata.Method, methodHandler);
            }
        }
示例#3
0
            internal void Remove(MulticastDelegate handler)
            {
                if (handler is null)
                {
                    throw new ArgumentNullException(nameof(handler));
                }

                if (Target != null && Target != handler.Target)
                {
                    throw new ArgumentException("如果代码没有写错,不可能在这里传入不一致的 Target。", nameof(handler));
                }

                Target = handler.Target;

                if (MethodHandlers.TryGetValue(handler.Method, out var handlers))
                {
                    handlers.RemoveAt(handlers.Count - 1);
                    if (handlers.Count == 0)
                    {
                        MethodHandlers.Remove(handler.Method);
                    }
                }
            }
示例#4
0
 internal IReadOnlyList <Action <TSender, TArgs> > GetInvokingHandlers()
 {
     return(MethodHandlers.SelectMany(x => x.Value).ToList());
 }