public override string ToString()
        {
            var mb = new MarkdownBuilder();

            mb.HeaderWithCode(1, Beautifier.BeautifyTypeWithLink(type, GenerateTypeRelativeLinkPath, false));
            mb.AppendLine();

            var desc = commentLookup[type.FullName].FirstOrDefault(x => x.MemberType == MemberType.Type)?.Summary ?? "";

            if (desc != "")
            {
                mb.AppendLine(desc);
            }
            {
                var sb = new StringBuilder();

                var stat = (type.IsAbstract && type.IsSealed) ? "static " : "";
                var abst = (type.IsAbstract && !type.IsInterface && !type.IsSealed) ? "abstract " : "";
                var classOrStructOrEnumOrInterface = type.IsInterface ? "interface" : type.IsEnum ? "enum" : type.IsValueType ? "struct" : "class";

                sb.AppendLine($"public {stat}{abst}{classOrStructOrEnumOrInterface} {Beautifier.BeautifyType(type, true)}");
                var impl = string.Join(", ", new[] { type.BaseType }.Concat(type.GetInterfaces()).Where(x => x != null && x != typeof(object) && x != typeof(ValueType)).Select(x => Beautifier.BeautifyType(x)));
                if (impl != "")
                {
                    sb.AppendLine("    : " + impl);
                }

                mb.Code("csharp", sb.ToString());
            }

            mb.AppendLine();

            if (type.IsEnum)
            {
                var enums = Enum.GetNames(type)
                            .Select(x => new {
                    Name = x,
                    //Value = ((Int32)Enum.Parse(type),
                    Value = x
                })
                            .OrderBy(x => x.Value)
                            .ToArray();

                BuildTable(mb, "Enum", enums, commentLookup[type.FullName], x => x.Value, x => x.Name, x => x.Name);
            }
            else
            {
                BuildTable(mb, "Fields", GetFields(), commentLookup[type.FullName], x => Beautifier.BeautifyTypeWithLink(x.FieldType, GenerateTypeRelativeLinkPath), x => x.Name, x => x.Name);
                BuildTable(mb, "Properties", GetProperties(), commentLookup[type.FullName], x => Beautifier.BeautifyTypeWithLink(x.PropertyType, GenerateTypeRelativeLinkPath), x => x.Name, x => x.Name);
                BuildTable(mb, "Events", GetEvents(), commentLookup[type.FullName], x => Beautifier.BeautifyTypeWithLink(x.EventHandlerType, GenerateTypeRelativeLinkPath), x => x.Name, x => x.Name);
                BuildTable(mb, "Constructors", GetConstructors(), commentLookup[type.FullName], x => "void", x => x.Name, x => Beautifier.ToMarkdownConstructorInfo(x, GenerateTypeRelativeLinkPath));
                BuildTable(mb, "Methods", GetMethods(), commentLookup[type.FullName], x => Beautifier.BeautifyTypeWithLink(x.ReturnType, GenerateTypeRelativeLinkPath), x => x.Name, x => Beautifier.ToMarkdownMethodInfo(x, GenerateTypeRelativeLinkPath));
                BuildTable(mb, "Static Fields", GetStaticFields(), commentLookup[type.FullName], x => Beautifier.BeautifyTypeWithLink(x.FieldType, GenerateTypeRelativeLinkPath), x => x.Name, x => x.Name);
                BuildTable(mb, "Static Properties", GetStaticProperties(), commentLookup[type.FullName], x => Beautifier.BeautifyTypeWithLink(x.PropertyType, GenerateTypeRelativeLinkPath), x => x.Name, x => x.Name);
                BuildTable(mb, "Static Methods", GetStaticMethods(), commentLookup[type.FullName], x => Beautifier.BeautifyTypeWithLink(x.ReturnType, GenerateTypeRelativeLinkPath), x => x.Name, x => Beautifier.ToMarkdownMethodInfo(x, GenerateTypeRelativeLinkPath));
                BuildTable(mb, "Static Events", GetStaticEvents(), commentLookup[type.FullName], x => Beautifier.BeautifyTypeWithLink(x.EventHandlerType, GenerateTypeRelativeLinkPath), x => x.Name, x => x.Name);
            }

            return(mb.ToString());
        }
Exemple #2
0
        public override string ToString()
        {
            var mb = new MarkdownBuilder();

            var desc = commentLookup[DeclaringType.FullName].FirstOrDefault(x => x.MemberType == MemberType.Method && x.MemberName == methodInfo.Name)?.Summary ?? "";

            if (desc != "")
            {
                mb.AppendLine(desc);
            }
            {
                var sb = new StringBuilder();

                var stat = (methodInfo.IsStatic) ? "static " : "";
                var abst = (methodInfo.IsAbstract) ? "abstract " : "";

                sb.AppendLine($"public {stat}{abst}{Returns} {NameWithParameters}");

                /*var impl = string.Join(", ", new[] { methodInfo.Name}.Concat(type.GetInterfaces()).Where(x => x != null && x != typeof(object) && x != typeof(ValueType)).Select(x => Beautifier.BeautifyType(x)));
                 * if (impl != "") {
                 *  sb.AppendLine("    : " + impl);
                 * }*/

                mb.Code("csharp", sb.ToString());
            }

            mb.AppendLine();

            BuildTable(mb, "Parameters", methodInfo.GetParameters(), commentLookup[DeclaringType.FullName], x => Beautifier.BeautifyType(x.ParameterType), x => x.Name, x => x.Name);
            return(mb.ToString());
        }
Exemple #3
0
        private string GeneralToString()
        {
            var mb = new MarkdownBuilder();

            mb.Header(2, Beautifier.BeautifyType(Type, false));
            mb.AppendLine();

            var summary = commentLookup[Type.FullName].FirstOrDefault(x => x.MemberType == MemberType.Type)?.Summary;

            if (!string.IsNullOrWhiteSpace(summary))
            {
                mb.Header(4, "Summary");
                mb.AppendLine(summary);
            }

            var remarks = commentLookup[Type.FullName].FirstOrDefault(x => x.MemberType == MemberType.Type)?.Remarks;

            if (!string.IsNullOrWhiteSpace(remarks))
            {
                mb.Header(4, "Remarks");
                mb.AppendLine(remarks);
            }

            { // Signature code.
                var stat = (Type.IsAbstract && Type.IsSealed) ? "static " : "";
                var abst = (Type.IsAbstract && !Type.IsInterface && !Type.IsSealed) ? "abstract " : "";
                var classOrStructOrEnumOrInterface = Type.IsInterface ? "interface" : Type.IsEnum ? "enum" : Type.IsValueType ? "struct" : "class";

                var sb = new StringBuilder();
                sb.AppendLine($"public {stat}{abst}{classOrStructOrEnumOrInterface} {Beautifier.BeautifyType(Type, true)}");
                var impl = string.Join(", ", new[] { Type.BaseType }.Concat(Type.GetInterfaces()).Where(x => x != null && x != typeof(object) && x != typeof(ValueType)).Select(x => Beautifier.BeautifyType(x)));
                if (impl != "")
                {
                    sb.AppendLine("    : " + impl);
                }

                mb.Code("csharp", sb.ToString());
                mb.AppendLine();
            }

            if (Type.IsEnum)
            {
                var enums = Enum.GetNames(Type)
                            .Select(x => new { Name = x, Value = (int)Enum.Parse(Type, x) })
                            .OrderBy(x => x.Value).ToArray();

                BuildTable(mb, "Enum", enums, commentLookup[Type.FullName], x => x.Value.ToString(), x => x.Name, x => x.Name);
            }
            else
            {
                BuildTable(mb, "Fields", GetFields(), commentLookup[Type.FullName], x => Beautifier.BeautifyType(x.FieldType), x => x.Name, x => x.Name);
                BuildTable(mb, "Properties", GetProperties(), commentLookup[Type.FullName], x => Beautifier.BeautifyType(x.PropertyType), x => x.Name, x => x.Name);
                BuildTable(mb, "Events", GetEvents(), commentLookup[Type.FullName], x => Beautifier.BeautifyType(x.EventHandlerType), x => x.Name, x => x.Name);
                BuildTable(mb, "Methods", GetMethods(), commentLookup[Type.FullName], x => Beautifier.BeautifyType(x.ReturnType), x => x.Name, x => Beautifier.ToMarkdownMethodInfo(x));
                BuildTable(mb, "Static Fields", GetStaticFields(), commentLookup[Type.FullName], x => Beautifier.BeautifyType(x.FieldType), x => x.Name, x => x.Name);
                BuildTable(mb, "Static Properties", GetStaticProperties(), commentLookup[Type.FullName], x => Beautifier.BeautifyType(x.PropertyType), x => x.Name, x => x.Name);
                BuildTable(mb, "Static Methods", GetStaticMethods(), commentLookup[Type.FullName], x => Beautifier.BeautifyType(x.ReturnType), x => x.Name, x => Beautifier.ToMarkdownMethodInfo(x));
                BuildTable(mb, "Static Events", GetStaticEvents(), commentLookup[Type.FullName], x => Beautifier.BeautifyType(x.EventHandlerType), x => x.Name, x => x.Name);
            }

            return(mb.ToString());
        }
Exemple #4
0
        private string CommandToString()
        {
            var mb = new MarkdownBuilder();

            if (HasCommandAlias)
            {
                mb.Header(2, CommandAlias);
            }
            else
            {
                var typeName = Beautifier.BeautifyType(Type, false);
                typeName = char.ToLowerInvariant(typeName[0]) + (typeName.Length > 1 ? typeName.Substring(1) : string.Empty);
                mb.Header(2, typeName);
            }
            mb.AppendLine();

            var summary = commentLookup[Type.FullName].FirstOrDefault(x => x.MemberType == MemberType.Type)?.Summary;

            if (!string.IsNullOrWhiteSpace(summary))
            {
                mb.Header(4, "Summary");
                mb.AppendLine(summary);
                mb.AppendLine();
            }

            var remarks = commentLookup[Type.FullName].FirstOrDefault(x => x.MemberType == MemberType.Type)?.Remarks;

            if (!string.IsNullOrWhiteSpace(remarks))
            {
                mb.Header(4, "Remarks");
                mb.AppendLine(remarks);
                mb.AppendLine();
            }

            // Params ----------------------------------------
            var parameters = GetParameters().Where(f => f.Name != "Wait" && f.Name != "ConditionalExpression");

            if (parameters.Count() > 0)
            {
                mb.Header(4, "Parameters");
                mb.Append("\n<div class=\"config-table\">\n\n");
                mb.Append("ID | Type | Description\n");
                mb.Append("--- | --- | ---\n");
                foreach (var parameter in parameters)
                {
                    var paramAlias = parameter.CustomAttributes.FirstOrDefault(a => a.AttributeType.Name == paramAliasAttrName)?.ConstructorArguments[0].Value as string;
                    var paramId    = paramAlias ?? parameter.Name;
                    var isNameless = paramId == string.Empty;
                    var isOptional = !parameter.CustomAttributes.Any(a => a.AttributeType.Name == requiredParamAttrName);
                    if (isNameless)
                    {
                        paramId = parameter.Name;
                    }
                    else
                    {
                        paramId = char.ToLowerInvariant(paramId[0]) + (paramId.Length > 1 ? paramId.Substring(1) : string.Empty);
                    }
                    if (isNameless || !isOptional)
                    {
                        var style = (isNameless ? "command-param-nameless " : string.Empty) + (!isOptional ? "command-param-required" : string.Empty);
                        style = style.Trim();
                        var title = (isNameless ? "Nameless parameter: value should be provided after the command identifer without specifying parameter ID " : string.Empty) +
                                    (!isOptional ? " Required parameter: parameter should always be specified" : string.Empty);
                        title   = title.Trim();
                        paramId = $"<span class=\"{style}\" title=\"{title}\">{paramId}</span>";
                    }

                    var typeName = Beautifier.BeautifyType(parameter.FieldType);

                    var doc      = default(XmlDocumentComment);
                    var baseType = Type;
                    while (baseType != null && doc is null)
                    {
                        var key = baseType.FullName != null && baseType.FullName.Contains("[") ? baseType.FullName.GetBefore("[") : baseType.FullName;
                        doc      = commentLookup[key].FirstOrDefault(x => x.MemberName == parameter.Name || x.MemberName.StartsWith(parameter.Name + "`"));
                        baseType = baseType.BaseType;
                    }
                    var descr = doc?.Summary ?? string.Empty;
                    mb.Append($"{paramId} | {typeName} | {descr}\n");
                }
                mb.Append("\n</div>\n\n");
            }
            // -----------------------------------------------

            var example = commentLookup[Type.FullName].FirstOrDefault(x => x.MemberType == MemberType.Type)?.Example;

            if (!string.IsNullOrWhiteSpace(example))
            {
                mb.Header(4, "Example");
                mb.Code(example);
                mb.AppendLine();
            }

            return(mb.ToString());
        }
        public override string ToString()
        {
            var mb = new MarkdownBuilder();

            var typeCategory = type.IsClass ? " Class" : type.IsInterface ? " Interface" : string.Empty;

            mb.HeaderWithCode(2, Beautifier.BeautifyType(type, false) + typeCategory);
            mb.AppendLine();
            mb.AppendLine($"Namespace: {type.Namespace}");
            mb.AppendLine();
            mb.AppendLine($"Assembly: {type.Assembly.ManifestModule.Name}");
            mb.AppendLine();

            var summary = commentLookup[type.FullName].FirstOrDefault(x => x.MemberType == MemberType.Type)?.Summary ?? "";

            if (summary != "")
            {
                mb.AppendLine(summary);
                mb.AppendLine();
            }

            var sb = new StringBuilder();

            var isStatic = type.IsAbstract && type.IsSealed;
            var @sealed  = !type.IsAbstract && type.IsSealed ? "sealed " : "";
            var stat     = isStatic ? "static " : "";
            var abst     = (type.IsAbstract && !type.IsInterface && !type.IsSealed) ? "abstract " : "";
            var classOrStructOrEnumOrInterface = type.IsInterface ? "interface" : type.IsEnum ? "enum" : type.IsValueType ? "struct" : "class";

            sb.AppendLine($"public {stat}{@sealed}{abst}{classOrStructOrEnumOrInterface} {Beautifier.BeautifyType(type, true)}");
            var impl = string.Join(", ", new[] { type.BaseType }.Concat(type.GetInterfaces()).Where(x => x != null && x != typeof(object) && x != typeof(ValueType)).Select(x => Beautifier.BeautifyType(x)));

            if (impl != "")
            {
                sb.AppendLine("    : " + impl);
            }

            mb.Code("csharp", sb.ToString());

            var typeParameters = commentLookup[type.FullName].FirstOrDefault(x => x.MemberType == MemberType.Type)?.TypeParameters;

            if (typeParameters.Count > 0)
            {
                mb.Header(3, "Type Parameters");
                mb.AppendLine();
                mb.Table(new[] { "Name", "Summary" }, typeParameters.Select(x => new[] { x.Key, x.Value }));
            }

            mb.AppendLine();

            if (type.IsEnum)
            {
                var underlyingEnumType = Enum.GetUnderlyingType(type);

                var enums = Enum.GetNames(type)
                            .Select(x => new { Name = x, Value = (Convert.ChangeType(Enum.Parse(type, x), underlyingEnumType)) })
                            .OrderBy(x => x.Value)
                            .ToArray();

                BuildTable(mb, "Enum", enums, commentLookup[type.FullName], x => x.Value.ToString(), x => x.Name, x => x.Name);
            }
            else
            {
                BuildTable(mb, "Constructors", GetConstructors(), commentLookup[type.FullName], x => Beautifier.BeautifyType(x.DeclaringType), x => "#ctor", x => Beautifier.ToMarkdownConstructorInfo(x));
                BuildTable(mb, "Fields", GetFields(), commentLookup[type.FullName], x => Beautifier.BeautifyType(x.FieldType), x => x.Name, x => x.Name);
                BuildTable(mb, "Properties", GetProperties(), commentLookup[type.FullName], x => Beautifier.BeautifyType(x.PropertyType), x => x.Name, x => x.Name);
                BuildTable(mb, "Events", GetEvents(), commentLookup[type.FullName], x => Beautifier.BeautifyType(x.EventHandlerType), x => x.Name, x => x.Name);
                BuildTable(mb, "Methods", GetMethods(), commentLookup[type.FullName], x => Beautifier.BeautifyType(x.ReturnType), x => x.Name, x => Beautifier.ToMarkdownMethodInfoWithoutParamNames(x));
                BuildTable(mb, "Static Fields", GetStaticFields(), commentLookup[type.FullName], x => Beautifier.BeautifyType(x.FieldType), x => x.Name, x => x.Name);
                BuildTable(mb, "Static Properties", GetStaticProperties(), commentLookup[type.FullName], x => Beautifier.BeautifyType(x.PropertyType), x => x.Name, x => x.Name);
                BuildTable(mb, "Static Methods", GetStaticMethods(), commentLookup[type.FullName], x => Beautifier.BeautifyType(x.ReturnType), x => x.Name, x => Beautifier.ToMarkdownMethodInfo(x));
                BuildTable(mb, "Static Events", GetStaticEvents(), commentLookup[type.FullName], x => Beautifier.BeautifyType(x.EventHandlerType), x => x.Name, x => x.Name);
            }

            return(mb.ToString());
        }
        public string BuildMethodPage(MethodInfo methodInfo)
        {
            var mb = new MarkdownBuilder();

            mb.HeaderWithCode(2, $"{Beautifier.BeautifyType(type)}.{Beautifier.ToMarkdownMethodInfoWithoutParamNames(methodInfo, true)} Method");
            mb.AppendLine();
            mb.AppendLine($"Namespace: {type.Namespace}");
            mb.AppendLine();
            mb.AppendLine($"Assembly: {type.Assembly.ManifestModule.Name}");
            mb.AppendLine();

            var comment = commentLookup[type.FullName].FirstOrDefault(x => x.MemberName == methodInfo.Name || x.MemberName.StartsWith(methodInfo.Name + "`"));

            var summary = comment?.Summary ?? string.Empty;

            if (summary != string.Empty)
            {
                mb.AppendLine(summary);
                mb.AppendLine();
            }

            var sb         = new StringBuilder();
            var stat       = methodInfo.IsStatic ? "static " : "";
            var abst       = methodInfo.IsAbstract ? "abstract " : "";
            var returnType = Beautifier.BeautifyType(methodInfo.ReturnType);

            sb.Append($"public {stat}{abst}{returnType} {Beautifier.ToMarkdownMethodInfo(methodInfo, true)}");
            mb.Code("csharp", sb.ToString());

            mb.AppendLine();

            if (comment.TypeParameters.Count > 0)
            {
                mb.Header(3, "Type Parameters");
                mb.AppendLine();
                foreach (var tp in comment.TypeParameters)
                {
                    mb.CodeQuote(tp.Key);
                    mb.AppendLine();
                    mb.AppendLine();
                    mb.AppendLine(tp.Value);
                }

                mb.AppendLine();
            }

            if (comment.Parameters.Count > 0)
            {
                mb.Header(3, "Parameters");
                mb.AppendLine();
                foreach (var parameter in comment.Parameters)
                {
                    mb.CodeQuote(parameter.Key);
                    mb.AppendLine();
                    mb.AppendLine();
                    mb.AppendLine(parameter.Value);
                }

                mb.AppendLine();
            }

            if (comment.Returns.Length > 0 && !comment.Returns.Equals("void"))
            {
                mb.Header(3, "Returns");
                mb.AppendLine();
                mb.CodeQuote(returnType);
                mb.AppendLine();
                mb.AppendLine();
                mb.AppendLine(comment.Returns);
            }

            return(mb.ToString());
        }