private MethodInfo getModuleMethod( RhspManager manager, string methodName, RhspParameterCollection rhspParams) { var nameQuery = from m in manager.GetType().GetMethods() where m.Name == methodName select m; if (nameQuery.Count() == 0) { throw new RhspException( "No methods exist with the name '" + methodName + "'."); } var paramCountQuery = from m in nameQuery where m.GetParameters().Length == rhspParams.Count select m; if (paramCountQuery.Count() == 0) { throw new RhspException( "None of the methods named '" + methodName + "' have " + "the same number of prameters as specified in the command."); } var paramNameQuery = from m in paramCountQuery where methodHasParamNames(m, rhspParams) select m; if (paramNameQuery.Count() == 0) { throw new RhspException( "The method with name '" + methodName + "' has the " + "correct number of parameters, but at least one of " + "either the parameter names or types do not match."); } var moduleMethodQuery = from m in paramNameQuery where hasModuleMethodAttribute(m) select m; if (moduleMethodQuery.Count() == 0) { throw new RhspException( "The method with name '" + methodName + "' has the correct number " + "of parameters and the correct parameter types, but does not implement " + "the attribute " + typeof(RhspModuleMethodAttribute).FullName + "."); } return(moduleMethodQuery.Single()); }
private bool methodHasParamNames(MethodInfo method, RhspParameterCollection rhspParams) { int validNameCount = 0; foreach (RhspParameter rhspParam in rhspParams.ToArray()) { if (methodHasParamName(method, rhspParam)) { validNameCount++; } } // Only true when the number of valid parameters matches the param count. return(validNameCount == method.GetParameters().Length); }