Exemplo n.º 1
0
            public override void VisitMember(Member member)
            {
                var    type       = member.Info as Type;
                var    methodInfo = member.Info as MethodInfo;
                string shortName;

                //                if (type != null && )
                if (type != null && IsBuiltinType(type, out shortName))
                {
                    var classWriter = new ClassWriter();
                    _classWriters[shortName] = classWriter;

                    _writer = classWriter.Head;

                    _writer.WriteLine("[:top:](#builtins)");
                    _writer.WriteLine();
                    _writer.WriteLine($"## `{shortName}` functions");
                    _writer.WriteLine();

                    base.VisitMember(member);

                    _writer = classWriter.Head;

                    _writer.WriteLine(_writerSummary);
                    _writer.WriteLine();

                    // Write the toc
                    _writerToc.WriteLine($"- [`{shortName}` functions](#{shortName}-functions)");
                }
                else if (methodInfo != null && IsBuiltinType(methodInfo.DeclaringType, out shortName))
                {
                    var methodShortName = StandardMemberRenamer.Default(methodInfo);

                    var classWriter = _classWriters[shortName];

                    // Write the toc
                    classWriter.Head.WriteLine($"- [`{shortName}.{methodShortName}`](#{shortName}{methodShortName})");

                    _writer = classWriter.Body;
                    _writer.WriteLine();
                    _writer.WriteLine("[:top:](#builtins)");
                    _writer.WriteLine($"### `{shortName}.{methodShortName}`");
                    _writer.WriteLine();
                    _writer.WriteLine("```");
                    _writer.Write($"{shortName}.{methodShortName}");
                    foreach (var parameter in methodInfo.GetParameters())
                    {
                        if (parameter.ParameterType == typeof(TemplateContext) || parameter.ParameterType == typeof(SourceSpan))
                        {
                            continue;
                        }
                        _writer.Write(" ");

                        _writer.Write($"<{parameter.Name}");
                        if (parameter.IsOptional)
                        {
                            var defaultValue = parameter.DefaultValue;
                            if (defaultValue is string)
                            {
                                defaultValue = "\"" + defaultValue + "\"";
                            }

                            if (defaultValue != null)
                            {
                                defaultValue = ": " + defaultValue;
                            }
                            _writer.Write($"{defaultValue}>?");
                        }
                        else
                        {
                            _writer.Write(">");
                        }
                    }
                    _writer.WriteLine();
                    _writer.WriteLine("```");
                    _writer.WriteLine();

                    base.VisitMember(member);

                    _writer = classWriter.Body;

                    // Write parameters after the signature
                    _writer.WriteLine("#### Description");
                    _writer.WriteLine();
                    _writer.WriteLine(_writerSummary);
                    _writer.WriteLine();
                    _writer.WriteLine("#### Arguments");
                    _writer.WriteLine();
                    _writer.WriteLine(_writerParameters);
                    _writer.WriteLine("#### Returns");
                    _writer.WriteLine();
                    _writer.WriteLine(_writerReturns);
                    _writer.WriteLine();
                    _writer.WriteLine("#### Examples");
                    _writer.WriteLine();
                    _writer.WriteLine(_writerRemarks);
                }

                _writerSummary    = new StringWriter();
                _writerParameters = new StringWriter();
                _writerReturns    = new StringWriter();
                _writerRemarks    = new StringWriter();
            }
Exemplo n.º 2
0
        public override void VisitMember(Member member)
        {
            var    type       = member.Info as Type;
            var    methodInfo = member.Info as MethodInfo;
            string shortName;

            //                if (type != null && )
            if (type != null && IsBuiltinType(type, out shortName))
            {
                var classWriter = new ClassWriter();
                _classWriters[shortName] = classWriter;

                _writer = classWriter.Head;

                _writer.WriteLine("[:top:](#builtins)");
                _writer.WriteLine();
                _writer.WriteLine("************************************************************************");
                _writer.WriteLine();
                _writer.WriteLine(string.Format("{0} functions", shortName));
                _writer.WriteLine("--------------");
                _writer.WriteLine();

                base.VisitMember(member);

                _writer = classWriter.Head;

                _writer.WriteLine(_writerSummary);
                _writer.WriteLine();

                // Write the toc
                _writerToc.WriteLine(string.Format("- [`{0}` functions](#{0}-functions)", shortName));
            }
            else if (methodInfo != null && IsBuiltinType(methodInfo.DeclaringType, out shortName))
            {
                var methodShortName = StandardMemberRenamer.Default(methodInfo);

                var classWriter = _classWriters[shortName];

                // Write the toc
                classWriter.Head.WriteLine(string.Format("- [`{0}.{1}`](#{0}{1})", shortName, methodShortName));

                _writer = classWriter.Body;
                _writer.WriteLine();
                _writer.WriteLine("[:top:](#builtins)");
                _writer.WriteLine();
                _writer.WriteLine("************************************************************************");
                _writer.WriteLine();
                _writer.WriteLine(string.Format("### `{0}.{1}`", shortName, methodShortName));
                _writer.WriteLine();
                _writer.WriteLine("#### SYNTAX");
                _writer.WriteLine("```");
                _writer.Write(string.Format("{0}.{1}", shortName, methodShortName));

                foreach (var parameter in methodInfo.GetParameters())
                {
                    if (parameter.ParameterType == typeof(TemplateContext) || parameter.ParameterType == typeof(SourceSpan))
                    {
                        continue;
                    }

                    _writer.Write(" ");

                    _writer.Write("<" + parameter.Name);
                    if (parameter.IsOptional)
                    {
                        var defaultValue = parameter.DefaultValue;
                        if (defaultValue is string)
                        {
                            defaultValue = "\"" + defaultValue + "\"";
                        }

                        if (defaultValue != null)
                        {
                            defaultValue = ": " + defaultValue;
                        }

                        _writer.Write(defaultValue + ">?");
                    }
                    else
                    {
                        _writer.Write(">");
                    }
                }
                _writer.WriteLine();
                _writer.WriteLine("```");
                _writer.WriteLine();

                base.VisitMember(member);

                _writer = classWriter.Body;

                // Write parameters after the signature
                _writer.WriteLine("#### DESCRIPTION");
                _writer.WriteLine(_writerSummary);
                _writer.WriteLine();
                _writer.WriteLine("#### PARAMETERS");
                _writer.WriteLine(_writerParameters);
                _writer.WriteLine();
                _writer.WriteLine("#### RETURNS");
                _writer.WriteLine(_writerReturns);
                _writer.WriteLine();
                _writer.WriteLine("#### EXAMPLES");
                _writer.WriteLine(_writerRemarks);
                _writer.WriteLine();
            }

            _writerSummary    = new StringWriter();
            _writerParameters = new StringWriter();
            _writerReturns    = new StringWriter();
            _writerRemarks    = new StringWriter();
        }