private IHandlerMethodResolver CreateResolverForAnnotation(Type attributeType) { IList <MethodInfo> methodsWithAnnotation = new List <MethodInfo>(); IList <MethodInfo> defaultCandidateMethods = HandlerMethodUtils.GetCandidateHandlerMethods(_obj); foreach (MethodInfo method in defaultCandidateMethods) { object[] annotations = method.GetCustomAttributes(attributeType, true); if (annotations != null && annotations.Length > 0) { methodsWithAnnotation.Add(method); } } IList <MethodInfo> candidateMethods = (methodsWithAnnotation.Count == 0) ? null : methodsWithAnnotation; if (candidateMethods == null) { if (logger.IsInfoEnabled) { logger.Info("Failed to find any valid Message-handling methods with annotation [" + attributeType + "] on target class [" + _obj.GetType() + "]. " + "Method-resolution will be applied to all eligible methods."); } candidateMethods = defaultCandidateMethods; } if (candidateMethods.Count == 1) { return(new StaticHandlerMethodResolver(candidateMethods[0])); } return(new PayloadTypeMatchingHandlerMethodResolver(candidateMethods)); }
private IHandlerMethodResolver CreateResolverForMethodName(string methodName) { IList <MethodInfo> methodsWithName = new List <MethodInfo>(); foreach (MethodInfo method in HandlerMethodUtils.GetCandidateHandlerMethods(_obj)) { if (method.Name.Equals(methodName)) { methodsWithName.Add(method); } } if (methodsWithName.Count == 0) { throw new ArgumentException("Failed to find any valid Message-handling methods named '" + methodName + "' on target class [" + _obj.GetType() + "]."); } if (methodsWithName.Count == 1) { return(new StaticHandlerMethodResolver(methodsWithName[0])); } return(new PayloadTypeMatchingHandlerMethodResolver(methodsWithName)); }