Exemplo n.º 1
0
        /// <summary>
        /// 创建监听Handler
        /// </summary>
        /// <param name="response">实例对象</param>
        /// <param name="methodName">方法名字</param>
        /// <returns></returns>
        private Action <ISFSObject> CreateHandler(AbsGameLogicBase response, string methodName)
        {
            Delegate action = Delegate.CreateDelegate(typeof(Action <ISFSObject>), response, methodName);

            if (null != action)
            {
                return(action as Action <ISFSObject>);
            }
            return(null);
        }
Exemplo n.º 2
0
        /// <summary>
        /// 获取响应事件
        /// </summary>
        /// <param name="methods">一个对象中的public方法</param>
        private void SeteHandlerAction(AbsGameLogicBase response, MethodInfo[] methods)
        {
            MethodInfo method;

            object[] handlerAtts;
            S2CResponseHandlerAttribute handlerAtt = null;

            foreach (MethodInfo item in methods)
            {
                method      = item;
                handlerAtts = method.GetCustomAttributes(typeof(S2CResponseHandlerAttribute), false);
                if (null == handlerAtts || handlerAtts.Length == 0)
                {
                    continue;
                }
                for (int i = 0; i < handlerAtts.Length; i++)
                {
                    handlerAtt = handlerAtts[i] as S2CResponseHandlerAttribute;
                    //先设置默认方法,如果有其他方法可用就表明是Gamekey所对于的方法
                    bool flag = handlerAtt.GameKey.Equals(MahjongUtility.GameKey);
                    if (handlerAtt.GameKey.Equals(MiscUtility.DefName) || flag)
                    {
                        if (mResponseHandlers.ContainsKey(handlerAtt.ProtocolKey))
                        {
                            if (flag)
                            {
                                Action <ISFSObject> handler = CreateHandler(response, method.Name);
                                if (null != handler)
                                {
                                    //替换handler
                                    mResponseHandlers[handlerAtt.ProtocolKey] = handler;
                                }
                            }
                        }
                        else
                        {
                            Action <ISFSObject> handler = CreateHandler(response, method.Name);
                            if (null != handler)
                            {
                                mResponseHandlers.Add(handlerAtt.ProtocolKey, handler);
                            }
                        }
                    }
                }
                //收集过滤事件
                handlerAtts = method.GetCustomAttributes(typeof(FilterOperateMenuAttribute), false);
                if (null != handlerAtts && handlerAtts.Length > 0)
                {
                    mSimpleFilter.Add(handlerAtt.ProtocolKey);
                }
            }
        }