Represents one usage of the described function.
コード例 #1
0
        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);
        }
コード例 #2
0
ファイル: HelpPrinter.cs プロジェクト: FlorianRappl/YAMP
        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);
            }
        }
コード例 #3
0
ファイル: Documentation.cs プロジェクト: FlorianRappl/YAMP
        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;
        }