public IEnumerable<object> GetParametersForMethod(Method method, IEnumerable<KeyValuePair<string,string>> parsedArguments) { var parameterInfos = method.GetParameters(); var parameters = new List<object>(); foreach (var paramInfo in parameterInfos) { if (paramInfo.IsClassAndNotString() && !paramInfo.IsFile()) { parameters.Add(CreateObjectFromArguments(parsedArguments, paramInfo)); } else { var recognizedArgument = parsedArguments.Where(a => a.Key.EqualsIC(paramInfo.Name)).ToArray(); parameters.Add(!recognizedArgument.Any() ? paramInfo.DefaultValue : ConvertFrom(recognizedArgument.Single(), paramInfo.ParameterType)); } } return parameters; }
public string Description(Controller t, Method method = null, bool includeArguments = false) { var description = t.Type.GetMethods().Where(m=> m.ReturnType.Equals( typeof(string)) && m.Name.EqualsIC( Conventions.Help) && m.GetParameters().Select(p=>p.ParameterType).SequenceEqual( new Type[] { typeof(string) })) .SingleOrDefault(); var descr = new List<string>(); if (null == description) { if (null == method) { descr.Add(_helpXmlDocumentation.GetDescriptionForType(t.Type)); } else { descr.Add(_helpXmlDocumentation.GetDescriptionForMethod(method.MethodInfo)); } } else { var obj = _container.CreateInstance(t.Type); descr.Add((string)description.Invoke(obj, new[] { (method != null ? method.Name : null) })); } if (method != null && includeArguments) { var arguments = method.GetArguments().Select(DescriptionAndHelp); descr.AddRange(arguments); } if (!descr.Any()) return string.Empty; return " " + String.Join(" ", descr).Trim(); }