public void GetParameterTypesWithNoArgHandler()
		{
			DelegateInfo del = new DelegateInfo(typeof (NoParametersHandler));
			Type[] types = del.GetParameterTypes();
			Assert.IsNotNull(types);
			Assert.AreEqual(0, types.Length);
		}
		public void GetParameterTypes()
		{
			DelegateInfo del = new DelegateInfo(typeof (FooHandler));
			Type[] types = del.GetParameterTypes();
			Assert.IsNotNull(types);
			Assert.AreEqual(3, types.Length);
		}
		public void GetReturnTypeWithNonVoidReturningDelegate()
		{
			DelegateInfo del = new DelegateInfo(typeof (FooHandler));
			Assert.AreEqual(typeof (string), del.GetReturnType());
		}
		public void IsSignatureCompatible()
		{
			DelegateInfo del = new DelegateInfo(typeof (FooHandler));
			MethodInfo method = GetType().GetMethod("DoFoo");
			Assert.IsFalse(del.IsSignatureCompatible(method));
		}
		public void GetReturnType()
		{
			DelegateInfo del = new DelegateInfo(typeof (EventHandler));
			Assert.AreEqual(typeof (void), del.GetReturnType());
		}
		public void IsSignatureCompatibleWithBadMethods()
		{
			DelegateInfo del = new DelegateInfo(typeof (FooHandler));

			// null method...
			MethodInfo method = GetType().GetMethod("SeaBass said that? Well, if that guy over there is SeaBass...");
			Assert.IsFalse(del.IsSignatureCompatible(method));

			// method that doesn;t have the required number of parameters...
			method = GetType().GetMethod("OddNumberOfParametersForFooHandler");
			Assert.IsFalse(del.IsSignatureCompatible(method));

			// method that doesn't have the required number of parameters...
			method = GetType().GetMethod("IncompatibleParametersForFooHandler");
			Assert.IsFalse(del.IsSignatureCompatible(method));
		}
		public void IsSignatureCompatibleWithInnerClassStaticMethod()
		{
			DelegateInfo del = new DelegateInfo(typeof (FooHandler));
			MethodInfo method =
				typeof (Yossarian).GetMethod(
					"DoFoo",
					BindingFlags.Public | BindingFlags.Static);
			Assert.IsTrue(del.IsSignatureCompatible(method));
		}
Example #8
0
        public void GetReturnTypeWithNonVoidReturningDelegate()
        {
            DelegateInfo del = new DelegateInfo(typeof(FooHandler));

            Assert.AreEqual(typeof(string), del.GetReturnType());
        }
Example #9
0
		/// <summary>
		/// Checks if the signature of the supplied <paramref name="handlerMethod"/>
		/// is compatible with the signature expected by the supplied
		/// <paramref name="eventMeta"/>.
		/// </summary>
		/// <param name="eventMeta">The event to be checked against.</param>
		/// <param name="handlerMethod">
		/// The method signature to check for compatibility.
		/// </param>
		/// <returns>
		/// <see langword="true"/> if the signature of the supplied
		/// <paramref name="handlerMethod"/> is compatible with the signature
		/// expected by the supplied <paramref name="eventMeta"/>;
		/// <see langword="false"/> if not or either of the supplied
		/// parameters is <see langword="null"/>. 
		/// </returns>
		/// <seealso cref="Spring.Util.DelegateInfo.IsSignatureCompatible(MethodInfo)"/>
		public static bool IsSignatureCompatible(
			EventInfo eventMeta, MethodInfo handlerMethod)
		{
			bool compatible = false;
			if (eventMeta != null
				&& DelegateInfo.IsDelegate(eventMeta.EventHandlerType))
			{
				compatible = new DelegateInfo(eventMeta.EventHandlerType)
					.IsSignatureCompatible(handlerMethod);
			}
			return compatible;
		}
Example #10
0
        public void GetReturnType()
        {
            DelegateInfo del = new DelegateInfo(typeof(EventHandler));

            Assert.AreEqual(typeof(void), del.GetReturnType());
        }
Example #11
0
 public void IsDelegate()
 {
     Assert.IsTrue(DelegateInfo.IsDelegate(typeof(EventHandler)));
 }
Example #12
0
 public void IsDelegateWithNullType()
 {
     Assert.IsFalse(DelegateInfo.IsDelegate(null));
 }
Example #13
0
 public void IsDelegateWithBadType()
 {
     Assert.IsFalse(DelegateInfo.IsDelegate(typeof(string)));
 }
			/// <summary>
			/// Wires up the supplied event to any handler methods that match the event
			/// signature.
			/// </summary>
			/// <param name="theEvent">The event being wired up.</param>
			private void WireEvent(EventInfo theEvent)
			{
				// grab some info (such as the delegate's method signature) about the event
				DelegateInfo eventDelegate = new DelegateInfo(theEvent);
				// if the method name needs to be customised on a per event basis, do so
				string customMethodName = GetMethodNameCustomisedForEvent(theEvent.Name);

				// create the criteria for the handler method search...
				ComposedCriteria methodCriteria = new ComposedCriteria();
				// a candidate handlers method name must match the custom method name
				methodCriteria.Add(new RegularExpressionMethodNameCriteria(customMethodName));
				// the return Type of a candidate handlers method must be the same as the return type of the event
				methodCriteria.Add(new MethodReturnTypeCriteria(eventDelegate.GetReturnType()));
				// a candidate handlers method parameters must match the event's parameters
				methodCriteria.Add(new MethodParametersCriteria(eventDelegate.GetParameterTypes()));

				// and grab the methods that satisfy the criteria...
				BindingFlags methodFlags = BindingFlags.Instance | BindingFlags.Static
					| BindingFlags.NonPublic | BindingFlags.Public;
				MemberInfo[] methods = HandlerType.FindMembers(
					MemberTypes.Method,
					methodFlags,
					new MemberFilter(new CriteriaMemberFilter().FilterMemberByCriteria),
					methodCriteria);

				// and for each method that satisfied the criteria...
				foreach (MethodInfo method in methods)
				{
					#region Instrumentation

					if (log.IsDebugEnabled)
					{
						log.Debug(string.Format(
							CultureInfo.InvariantCulture,
							"Wiring up this method '{0}' to this event '{1}'",
							method.Name,
							theEvent.Name));
					}

					#endregion

					IEventHandlerValue myHandler = method.IsStatic ?
						(IEventHandlerValue) new StaticEventHandlerValue() :
						(IEventHandlerValue) new InstanceEventHandlerValue();
					myHandler.EventName = theEvent.Name;
					myHandler.MethodName = method.Name;
					myHandler.Wire(Source, Handler);
				}
			}