Ejemplo n.º 1
0
        public void Compose()
        {
            var types  = typeof(SizeUnit).Assembly.GetTypes().Where(t => t.Namespace == typeof(SizeUnit).Namespace).OrderBy(x => x.Name).ToArray();
            var writer = new PageWriter();

            writer.WriteTableOfContent(types.Select(x => x.Name));

            foreach (var type in types)
            {
                writer.WriteHeader(type.Name, 2);
                writer.WriteDescription(type.GetCustomAttribute <DescriptionAttribute>());

                if (type.IsEnum)
                {
                    writer.Write("Enum values: ").WriteLine(string.Join(", ", Enum.GetNames(type).Select(n => $"`{n}`")));
                }
                writer.WriteLine();

                if (ParseMethods.TryGetValue(type, out var method))
                {
                    var parseDescription = method.GetCustomAttribute <DescriptionAttribute>();
                    if (parseDescription != null)
                    {
                        writer.WriteLine("**Parse rules:**").WriteLine().WriteDescription(parseDescription).WriteLine();
                    }
                }
            }

            File.WriteAllText("man\\Types.md", writer.ToString());
        }
Ejemplo n.º 2
0
 private string LinkType(Type type)
 {
     if (type.Assembly == typeof(Component).Assembly)
     {
         return($"[{type.Name}]({_typesFileLink}#{PageWriter.ToAnchor(type.Name)})");
     }
     return(type.FullName);
 }
Ejemplo n.º 3
0
        private async Task EmbedLongDescription(Type type, PageWriter writer)
        {
            var file = $"{AppContext.BaseDirectory}\\components\\{type.Name}.md";

            if (File.Exists(file))
            {
                writer.WriteLine("**Sample usage:**").WriteLine().WriteLine(await new MarkdownCompiler(file).Compile());
            }
        }
Ejemplo n.º 4
0
        public async Task Compose()
        {
            var components = typeof(Component).Assembly
                             .GetTypes()
                             .Where(t => typeof(Component).IsAssignableFrom(t) && !t.IsAbstract)
                             .OrderBy(t => t.Name)
                             .GroupBy(GetInterface)
                             .OrderByDescending(x => Array.IndexOf(Interfaces, x.Key))
                             .ToArray();

            var writer = new PageWriter();

            foreach (var group in components)
            {
                writer.WriteLine($"* {group.Key.Name}");
                writer.WriteTableOfContent(group.Select(x => x.Name), 1);
            }

            foreach (var group in components)
            {
                writer.WriteHeader(group.Key.Name, 2);
                writer.WriteDescription(group.Key.GetCustomAttribute <DescriptionAttribute>());
                writer.WriteLine();

                foreach (var type in group)
                {
                    writer.WriteHeader(type.Name, 3);
                    writer.WriteLine($"Implements: `{GetInterface(type).Name}`").WriteLine();
                    writer.WriteDescription(type.GetCustomAttribute <DescriptionAttribute>());

                    await EmbedLongDescription(type, writer);

                    writer.WriteHeader($"{type.Name} members", 3);

                    writer.WriteTable(new[] { "Member", "Type", "Default value", "Description" }, ReadMembers(type));
                }
            }
            File.WriteAllText("man\\Components.md", writer.ToString());
        }