Esempio n. 1
0
        /// <summary>
        ///     Gets markdown string of given type.
        ///     It includes type reference.
        /// </summary>
        internal static string GetTypeMarkdown(Type t, bool quote = true, string fixedName = null)
        {
            var name     = string.Empty;
            var typeName = DocSyntax.FixVarName(t.Name); // fix type name

            if (t.IsByRef)
            {
                typeName = typeName.Remove(typeName.Length - 1, 1);
                typeName = $"ref {typeName}";
            }

            if (!string.IsNullOrEmpty(fixedName))
            {
                typeName += $" {fixedName}";
            }

            if (!CanDefineTypeReference(t))
            {
                if (quote)
                {
                    name += "`";
                }
                name += typeName;
                if (quote)
                {
                    name += "`";
                }
                name += " ";
            }
            else
            {
                name += "[";
                if (quote)
                {
                    name += "`";
                }
                name += typeName;
                if (quote)
                {
                    name += "`";
                }
                name += $"]({DocSyntax.CollectMarkDownReference(t)})";
            }

            return(name);
        }
Esempio n. 2
0
        private string BuildType(Type t)
        {
            if (!t.IsVisible)
            {
                Program.Process($"Target type ({t.Name}) is not visible!", true);
                return(null);
            }

            if (DocBuilderHelper.IsTypeArrayContainsNotAllowed(t))
            {
                Program.Process($"Target type ({t.Name}) is not allowed to be generated!", true);
                return(null);
            }

            var fileName = DocSyntax.CollectTypeName(t);
            var filePath = DocSyntax.GetMarkdownFile($"{DeployDir}{JEMVar.DirectorySeparatorChar}{fileName}");

            if (DocSyntax.FixVarName(ref filePath))
            {
                Program.Process($"Target type ({t.Name}) has invalid filePath ({filePath}).", true);
                return(null);
            }

            var str    = new StringBuilder();
            var subStr = new StringBuilder();

            if (t.IsClass)
            {
                Program.Process($"New class: {t.Name}");

                // HEADER
                str.AppendLine($"# {t.Name}");
                if (t.BaseType != null && t.BaseType != typeof(object))
                {
                    str.AppendLine($"<small>class in `{Path.GetFileNameWithoutExtension(new Uri(t.Assembly.CodeBase).AbsolutePath)}` " +
                                   $"/ inherits from {DocClassUtil.GetTypeMarkdown(t.BaseType, false)}</small>");
                }
                else
                {
                    str.AppendLine($"<small>{(t.IsAbstract && t.IsSealed ? "static " : string.Empty)}class in `{Path.GetFileNameWithoutExtension(new Uri(t.Assembly.CodeBase).AbsolutePath)}`</small>");
                }
                str.AppendLine(string.Empty);

                // SUMMARY
                DocXmlUtil.CollectSummaryFromNode(_nodes, t.FullName, out var classSummary);
                str.AppendLine("### Description");
                str.AppendLine(classSummary);

                // EVENTS
                DocBuilderHelper.BuildEvents(t, str, _nodes, TypeContent.Target, false);
                // FIELDS
                DocBuilderHelper.BuildFields(t, str, _nodes, TypeContent.Target, false);
                // PROPERTIES
                DocBuilderHelper.BuildProperties(t, str, _nodes, TypeContent.Target, false);
                // METHODS
                DocBuilderHelper.BuildMethods(t, str, _nodes, TypeContent.Target, false);

                // STATIC EVENTS
                DocBuilderHelper.BuildEvents(t, str, _nodes, TypeContent.Target, true);
                // STATIC FIELDS
                DocBuilderHelper.BuildFields(t, str, _nodes, TypeContent.Target, true);
                // STATIC PROPERTIES
                DocBuilderHelper.BuildProperties(t, str, _nodes, TypeContent.Target, true);
                // STATIC METHODS
                DocBuilderHelper.BuildMethods(t, str, _nodes, TypeContent.Target, true);

                subStr.Clear();
                // INHERITED MEMBERS
                // EVENTS
                DocBuilderHelper.BuildEvents(t, str, _nodes, TypeContent.Inherited, false);
                // INHERITED MEMBERS
                // FIELDS
                DocBuilderHelper.BuildFields(t, subStr, _nodes, TypeContent.Inherited, false);
                // INHERITED MEMBERS
                // PROPERTIES
                DocBuilderHelper.BuildProperties(t, subStr, _nodes, TypeContent.Inherited, false);
                // INHERITED MEMBERS
                // METHODS
                DocBuilderHelper.BuildMethods(t, subStr, _nodes, TypeContent.Inherited, false);

                // INHERITED MEMBERS
                // STATIC EVENTS
                DocBuilderHelper.BuildEvents(t, str, _nodes, TypeContent.Inherited, true);
                // INHERITED MEMBERS
                // STATIC FIELDS
                DocBuilderHelper.BuildFields(t, subStr, _nodes, TypeContent.Inherited, true);
                // INHERITED MEMBERS
                // STATIC PROPERTIES
                DocBuilderHelper.BuildProperties(t, subStr, _nodes, TypeContent.Inherited, true);
                // INHERITED MEMBERS
                // STATIC METHODS
                DocBuilderHelper.BuildMethods(t, subStr, _nodes, TypeContent.Inherited, true);

                if (!string.IsNullOrEmpty(subStr.ToString()) && !string.IsNullOrWhiteSpace(subStr.ToString()))
                {
                    str.AppendLine();
                    str.AppendLine();
                    str.AppendLine("## Inherited Members");
                    str.AppendLine(subStr.ToString());
                }

                // EXAMPLES
                BuildExample(t, str);
            }
            else if (t.IsEnum)
            {
                Program.Process($"New Enum: {t.Name}");

                // HEADER
                str.AppendLine($"# {t.Name}");
                if (t.BaseType != null && t.BaseType != typeof(Object))
                {
                    str.AppendLine($"<small>enumeration in `{Path.GetFileNameWithoutExtension(new Uri(t.Assembly.CodeBase).AbsolutePath)}`</small>");
                }
                str.AppendLine(string.Empty);

                // SUMMARY
                DocXmlUtil.CollectSummaryFromNode(_nodes, t.FullName, out var classSummary);
                str.AppendLine("### Description");
                str.AppendLine(classSummary);

                // PROPERTIES
                DocBuilderHelper.BuildEnum(t, str, _nodes);

                // EXAMPLES
                BuildExample(t, str);
            }

            if (File.Exists(AppConfig.Loaded.FileEnd))
            {
                str.AppendLine();
                str.AppendLine(File.ReadAllText(AppConfig.Loaded.FileEnd));
            }

            WriteAllText(filePath, str.ToString());
            return(fileName);
        }