public void SetUp()
		{
			_wmHandlerList = new NuGenWmHandlerList();

			_m = new Message();
			_m.HWnd = (IntPtr)0x0001;
			_m.Msg = WM_LBUTTONDOWN;
		}
			public WmSink(NuGenWmHandlerList wmHandlerList)
			{
				if (wmHandlerList == null)
				{
					Assert.Fail("wmHandlerList cannot be null.");
				}

				wmHandlerList.AddWmHandler(WM_LBUTTONDOWN, this.WmHandler);
				wmHandlerList.AddWmHandler(WM_LBUTTONDOWN, this.WmHandler2);
			}
        public void GetEnumeratorTest()
        {
            _wmHandlerList.AddWmHandler(WM_LBUTTONDOWN, this.StubWmHandler);
            _wmHandlerList.AddWmHandler(WM_LBUTTONUP, this.StubWmHandler2);

            NuGenWmHandlerList wmHandlerList2 = new NuGenWmHandlerList();

            wmHandlerList2.AddWmHandler(WM_LBUTTONDOWN, this.StubWmHandler);
            wmHandlerList2.AddWmHandler(WM_LBUTTONUP, this.StubWmHandler2);

            foreach (int wmId in _wmHandlerList)
            {
                Assert.AreEqual(wmHandlerList2[wmId], _wmHandlerList[wmId]);
            }
        }
		/// <summary>
		/// Looks for methods marked with <see cref="NuGenWmHandlerAttribute"/> and initializes a message map
		/// of type <see cref="NuGenWmHandlerList"/>.
		/// </summary>
		/// 
		/// <param name="messageProcessor">
		/// Specifies the methods marked with <see cref="NuGenWmHandlerAttribute"/> attribute(s)
		/// to handle Windows messages.
		/// </param>
		/// 
		/// <exception cref="ArgumentNullException">
		/// <paramref name="messageProcessor"/> is <see langword="null"/>.
		/// </exception>
		/// 
		/// <exception cref="NuGenWmHandlerSignatureException">
		/// <paramref name="messageProcessor"/> provides a method marked with <see cref="NuGenWmHandlerAttribute"/>
		/// but not compatible with the <see cref="NuGenWmHandler"/> delegate.
		/// </exception>
		public NuGenWmHandlerList BuildMessageMap(INuGenMessageProcessor messageProcessor)
		{
			if (messageProcessor == null)
			{
				throw new ArgumentNullException("messageProcessor");
			}

			NuGenWmHandlerList handlerList = new NuGenWmHandlerList();

			MethodInfo[] methods = messageProcessor.GetType().GetMethods(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);

			for (int i = 0; i < methods.Length; i++)
			{
				MethodInfo method = methods[i];
				object[] attributes = method.GetCustomAttributes(typeof(NuGenWmHandlerAttribute), false);

				if (attributes != null)
				{
					foreach (NuGenWmHandlerAttribute attribute in attributes)
					{
						string methodName = method.Name;
						NuGenWmHandler wmHandler = null;

						try
						{
							wmHandler = (NuGenWmHandler)NuGenWmHandler.CreateDelegate(
								typeof(NuGenWmHandler),
								messageProcessor,
								methodName,
								false,
								true
							);
						}
						catch (ArgumentException)
						{
							throw new NuGenWmHandlerSignatureException(methodName);
						}

						handlerList.AddWmHandler(
							attribute.WmId,
							wmHandler
						);
					}
				}
			}

			return handlerList;
		}
Exemplo n.º 5
0
        /// <summary>
        /// Looks for methods marked with <see cref="NuGenWmHandlerAttribute"/> and initializes a message map
        /// of type <see cref="NuGenWmHandlerList"/>.
        /// </summary>
        ///
        /// <param name="messageProcessor">
        /// Specifies the methods marked with <see cref="NuGenWmHandlerAttribute"/> attribute(s)
        /// to handle Windows messages.
        /// </param>
        ///
        /// <exception cref="ArgumentNullException">
        /// <paramref name="messageProcessor"/> is <see langword="null"/>.
        /// </exception>
        ///
        /// <exception cref="NuGenWmHandlerSignatureException">
        /// <paramref name="messageProcessor"/> provides a method marked with <see cref="NuGenWmHandlerAttribute"/>
        /// but not compatible with the <see cref="NuGenWmHandler"/> delegate.
        /// </exception>
        public NuGenWmHandlerList BuildMessageMap(INuGenMessageProcessor messageProcessor)
        {
            if (messageProcessor == null)
            {
                throw new ArgumentNullException("messageProcessor");
            }

            NuGenWmHandlerList handlerList = new NuGenWmHandlerList();

            MethodInfo[] methods = messageProcessor.GetType().GetMethods(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);

            for (int i = 0; i < methods.Length; i++)
            {
                MethodInfo method     = methods[i];
                object[]   attributes = method.GetCustomAttributes(typeof(NuGenWmHandlerAttribute), false);

                if (attributes != null)
                {
                    foreach (NuGenWmHandlerAttribute attribute in attributes)
                    {
                        string         methodName = method.Name;
                        NuGenWmHandler wmHandler  = null;

                        try
                        {
                            wmHandler = (NuGenWmHandler)NuGenWmHandler.CreateDelegate(
                                typeof(NuGenWmHandler),
                                messageProcessor,
                                methodName,
                                false,
                                true
                                );
                        }
                        catch (ArgumentException)
                        {
                            throw new NuGenWmHandlerSignatureException(methodName);
                        }

                        handlerList.AddWmHandler(
                            attribute.WmId,
                            wmHandler
                            );
                    }
                }
            }

            return(handlerList);
        }
			public WmSinkRemove(NuGenWmHandlerList wmHandlerList)
				: base(wmHandlerList)
			{
				if (wmHandlerList == null)
				{
					Assert.Fail("wmHandlerList cannot be null.");
				}

				wmHandlerList.RemoveWmHandler(WM_LBUTTONDOWN, this.WmHandler);
			}