Пример #1
0
        private void ParseClass(Type type, XmlDocTree xmlDocTree)
        {
            ClassTypeDoc classType = new ClassTypeDoc()
            {
                Name           = type.Name,
                Type           = type,
                Namespace      = type.Namespace,
                IsGeneric      = type.IsGenericType,
                IsStatic       = type.IsAbstract && type.IsSealed,
                IsAbstract     = type.IsAbstract,
                IsSealed       = type.IsSealed,
                Obsolete       = type.IsDefined(typeof(ObsoleteAttribute), true),
                ObsoleteString = type.GetCustomAttribute <ObsoleteAttribute>(true)?.Message
            };

            foreach (MethodInfo method in type.GetMethods(BindingFlags.Instance | BindingFlags.Public | BindingFlags.Static).Where(x => !x.IsSpecialName))
            {
                classType.Methods.Add(ParseMethod(type, method, xmlDocTree));
            }

            foreach (FieldInfo field in type.GetFields(BindingFlags.Instance | BindingFlags.Public | BindingFlags.Static))
            {
                classType.Fields.Add(ParseField(type, field, xmlDocTree));
            }

            foreach (PropertyInfo property in type.GetProperties(BindingFlags.Instance | BindingFlags.Public | BindingFlags.Static))
            {
                classType.Properties.Add(ParseProperty(type, property, xmlDocTree));
            }

            foreach (ConstructorInfo constructor in type.GetConstructors(BindingFlags.Instance | BindingFlags.Public | BindingFlags.Static))
            {
                classType.Constructors.Add(ParseConstructor(type, constructor, xmlDocTree));
            }

            DocMember member = xmlDocTree.GetDocumentation(type);

            if (member != null)
            {
                classType.Summary = member.Summary;
            }

            docTypes.Add(classType);
        }
Пример #2
0
        private static void PrintClass(StringBuilder b, ClassTypeDoc type, DocTree tree)
        {
            b.AppendLine("<div style=\"line-height: 1;\">");
            b.AppendLine("\t<h2 markdown=\"1\">" + Utils.GetSafeTypeName(type.Type, true) + " ``class``" + (type.Obsolete ? " <small><span class=\"label label-warning\" title=\"" + type.ObsoleteString + "\">Obsolete</span></small>" : "") + "</h2>");
            b.AppendLine("\t<p style=\"font-size: 20px;\"><b>Namespace:</b> " + type.Namespace + "</p>");
            b.AppendLine("\t<p style=\"font-size: 20px;\"><b>Assembly:</b> MLAPI.dll</p>");
            b.AppendLine("</div>");

            if (type.Summary != null)
            {
                b.AppendLine("<p>" + type.Summary + "</p>");
                b.AppendLine();
            }

            PrintProperties(b, type.Properties, tree);
            PrintFields(b, type.Fields, tree);
            PrintConstructors(b, type.Constructors, tree);
            PrintMethods(b, type.Methods, tree);
        }
Пример #3
0
        public static void Print(DocTree tree, string yamlPath, string apiFolder)
        {
            List <DocType> apis = new List <DocType>();

            for (int i = 0; i < tree.docTypes.Count; i++)
            {
                if (tree.docTypes[i] is ClassTypeDoc)
                {
                    ClassTypeDoc type = (ClassTypeDoc)tree.docTypes[i];

                    apis.Add(type);

                    StringBuilder b = new StringBuilder();
                    b.AppendLine("---");
                    b.AppendLine("title: " + Utils.GetSafeTypeName(type.Type, true));
                    b.AppendLine("name: " + Utils.GetSafeTypeName(type.Type, false));
                    b.AppendLine("permalink: " + Utils.GetRelativeApiUrl(type.Type));
                    b.AppendLine("---");
                    b.AppendLine();

                    PrintClass(b, type, tree);

                    File.WriteAllText(Path.Combine(apiFolder, Utils.GetSafeTypeName(type.Type, false).Replace("<", "_").Replace(">", "_") + ".md"), b.ToString());
                }
                else if (tree.docTypes[i] is EnumTypeDoc)
                {
                    EnumTypeDoc type = (EnumTypeDoc)tree.docTypes[i];

                    apis.Add(type);

                    StringBuilder b = new StringBuilder();
                    b.AppendLine("---");
                    b.AppendLine("title: " + Utils.GetSafeTypeName(type.Type, true));
                    b.AppendLine("name: " + Utils.GetSafeTypeName(type.Type, false));
                    b.AppendLine("permalink: " + Utils.GetRelativeApiUrl(type.Type));
                    b.AppendLine("---");
                    b.AppendLine();

                    PrintEnum(b, type);

                    File.WriteAllText(Path.Combine(apiFolder, Utils.GetSafeTypeName(type.Type, false).Replace("<", "_").Replace(">", "_") + ".md"), b.ToString());
                }
                else if (tree.docTypes[i] is StructDocType)
                {
                    StructDocType type = (StructDocType)tree.docTypes[i];

                    apis.Add(type);

                    StringBuilder b = new StringBuilder();
                    b.AppendLine("---");
                    b.AppendLine("title: " + Utils.GetSafeTypeName(type.Type, true));
                    b.AppendLine("name: " + Utils.GetSafeTypeName(type.Type, false));
                    b.AppendLine("permalink: " + Utils.GetRelativeApiUrl(type.Type));
                    b.AppendLine("---");
                    b.AppendLine();

                    PrintStruct(b, type, tree);

                    File.WriteAllText(Path.Combine(apiFolder, Utils.GetSafeTypeName(type.Type, false).Replace("<", "_").Replace(">", "_") + ".md"), b.ToString());
                }
            }

            StringBuilder builder = new StringBuilder();

            WriteYaml(builder, apis);

            File.WriteAllText(yamlPath, builder.ToString());
        }