예제 #1
0
파일: Dispatcher.cs 프로젝트: Riul/emulator
        public void Register(MethodInfo method, object instance, MessageHandlerAttribute[] attributes)
        {
            if (method == null)
            {
                throw new ArgumentNullException("method");
            }
            if (instance == null)
            {
                throw new ArgumentNullException("instance");
            }
            if (attributes == null || attributes.Length == 0)
            {
                return;
            }

            ParameterInfo[] parameters = method.GetParameters();
            if (parameters.Length != 1)
            {
                throw new Exception(string.Format("Only one parameter is allowed to use the MessageHandler attribute. (method {0})", method.Name));
            }
            if (!parameters[0].ParameterType.IsSubclassOf(typeof(NetworkMessage)))
            {
                throw new Exception(string.Format("The parameter of a MessageHandler attribute must be a child of NetworkMessage. (method {0})", method.Name));
            }
            methods.Add(new MethodHandler(method, instance, attributes));
        }
예제 #2
0
 public MethodHandler(MethodInfo method, object instance, MessageHandlerAttribute[] attributes)
 {
     Method = method;
     Instance = instance;
     Attributes = attributes;
 }