HelpFunctionUsage GetUsage(String name, MethodInfo function) { var objects = function.GetCustomAttributes(typeof(ExampleAttribute), false); var rets = function.GetCustomAttributes(typeof(ReturnsAttribute), false); var help = new HelpFunctionUsage(); var args = function.GetParameters(); if (rets.Length == 0) { help.Returns.Add(ModifyValueType(function.ReturnType)); } else { rets = rets.OrderBy(m => ((ReturnsAttribute)m).Order).ToArray(); foreach (ReturnsAttribute attribute in rets) { var expl = GetLocalized(attribute.ExplanationKey); var content = String.Concat(ModifyValueType(attribute.ReturnType), " : ", expl); help.Returns.Add(content); } } help.Description = GetDescription(function); var sb = new StringBuilder(); foreach (var arg in args) { help.ArgumentNames.Add(arg.Name); help.Arguments.Add(ModifyValueType(arg.ParameterType)); } sb.Append(name).Append("("); sb.Append(String.Join(",", help.ArgumentNames.ToArray())); sb.AppendLine(")"); help.Usage = sb.ToString(); foreach (ExampleAttribute attribute in objects) { help.Examples.Add(GetExample(attribute)); } return(help); }
void PrintUsage(HelpFunctionUsage usage) { if (usage != null) { formatter.AddUsage(usage.Usage); formatter.AddDescription(usage.Description); for (var i = 0; i < usage.ArgumentNames.Count; i++) { formatter.AddArgument(usage.ArgumentNames[i]); formatter.AddDescription(usage.Arguments[i]); } for (var i = 0; i < usage.Returns.Count; i++) { formatter.AddReturn((i + 1) + ". entry"); formatter.AddDescription(usage.Returns[i]); } PrintExamples(usage.Examples); } }
HelpFunctionUsage GetUsage(String name, MethodInfo function) { var objects = function.GetCustomAttributes(typeof(ExampleAttribute), false); var rets = function.GetCustomAttributes(typeof(ReturnsAttribute), false); var help = new HelpFunctionUsage(); var args = function.GetParameters(); if (rets.Length == 0) { help.Returns.Add(ModifyValueType(function.ReturnType)); } else { rets = rets.OrderBy(m => ((ReturnsAttribute)m).Order).ToArray(); foreach (ReturnsAttribute attribute in rets) { var expl = GetLocalized(attribute.ExplanationKey); var content = String.Concat(ModifyValueType(attribute.ReturnType), " : ", expl); help.Returns.Add(content); } } help.Description = GetDescription(function); var sb = new StringBuilder(); foreach (var arg in args) { help.ArgumentNames.Add(arg.Name); help.Arguments.Add(ModifyValueType(arg.ParameterType)); } sb.Append(name).Append("("); sb.Append(String.Join(",", help.ArgumentNames.ToArray())); sb.AppendLine(")"); help.Usage = sb.ToString(); foreach (ExampleAttribute attribute in objects) { help.Examples.Add(GetExample(attribute)); } return help; }