Example #1
0
        static void Main(string[] args)
        {
            var(assemblyName, typeName, outputFile, format, ignoreMethods, ignoreAttributes, recursive, recursiveAssemblies) = Parse(args);
            if (assemblyName == null)
            {
                Help();
                return;
            }

            var writer = MarkdownWriters.FirstOrDefault(md => md.FormatName.Equals(format, StringComparison.OrdinalIgnoreCase));

            if (format == null)
            {
                writer = MarkdownWriters.First();
                Console.WriteLine($"Markdown format not specified. Assuming {writer.FormatName}.");
            }
            if (writer == null)
            {
                Console.WriteLine($"Error: invalid markdown format specified. Valid values: {MarkdownFormatNames}");
                return;
            }

            try
            {
                var myAssembly = Assembly.LoadFrom(assemblyName);
                if (myAssembly == null)
                {
                    throw new Exception($"Could not load assembly \'{assemblyName}\'");
                }

                Type rootType = null;
                if (typeName != null)
                {
                    rootType = myAssembly.DefinedTypes.FirstOrDefault(t => t.Name == typeName);
                    if (rootType == null)
                    {
                        var possibleTypes = myAssembly.DefinedTypes
                                            .Where(t => t.Name.Contains(typeName, StringComparison.OrdinalIgnoreCase))
                                            .Select(t => t.Name).ToList();
                        if (possibleTypes.Count == 0)
                        {
                            throw new Exception(
                                      $"Specified type name \'{typeName}\' not found in assembly \'{assemblyName}\'");
                        }

                        throw new Exception(
                                  $"Specified type name \'{typeName}\' not found in assembly \'{assemblyName}\'." +
                                  $" Similar type names in the assembly: {string.Join(",", possibleTypes)}");
                    }
                }
                DocumentationGenerator.GenerateMarkdown(rootType,
                                                        rootType == null ? myAssembly : null, recursive, recursiveAssemblies, ignoreAttributes, ignoreMethods, writer, outputFile);
            }
            catch (Exception exc)
            {
                Console.WriteLine($"Error: {exc.Message}");
                Console.WriteLine($"{exc.StackTrace}");
            }
        }
Example #2
0
        public static void GenerateMarkdown(
            Type rootType,
            Assembly assembly,
            bool recursiveAssemblyTraversal,
            List <string> recursiveAssemblies,
            List <string> ignoreAttributes,
            bool ignoreMethods,
            IMarkdownWriter markdownWriter,
            string outputFileName)
        {
            // Reflection setup
            var allAssemblyTypes = assembly != null;

            if (assembly == null)
            {
                assembly = rootType.Assembly;
            }
            var ignoreAttributesHash = ignoreAttributes == null || ignoreAttributes.Count == 0 ? null : new HashSet <string>(ignoreAttributes);

            var reflectionSettings = ReflectionSettings.Default;
            var prevPropertyFilter = reflectionSettings.PropertyFilter;

            reflectionSettings.PropertyFilter = info =>
                                                (prevPropertyFilter == null || prevPropertyFilter(info)) && !HasIgnoreAttribute(info, ignoreAttributesHash);
            reflectionSettings.MethodFilter   = info => !ignoreMethods && !HasIgnoreAttribute(info, ignoreAttributesHash);
            reflectionSettings.TypeFilter     = type => !HasIgnoreAttribute(type, ignoreAttributesHash);
            reflectionSettings.AssemblyFilter =
                reflectionAssembly => reflectionAssembly == assembly || recursiveAssemblyTraversal &&
                (recursiveAssemblies == null || recursiveAssemblies.Count == 0 ||
                 recursiveAssemblies.Any(name => name.Equals(Path.GetFileName(assembly.Location), StringComparison.OrdinalIgnoreCase)));

            // Reflection
            var typeCollection = allAssemblyTypes ?
                                 TypeCollection.ForReferencedTypes(assembly, reflectionSettings) :
                                 TypeCollection.ForReferencedTypes(rootType, reflectionSettings);

            // Generate markdown
            var generator = new DocumentationGenerator(markdownWriter, typeCollection, rootType);

            if (assembly != null)
            {
                generator.WriteDocumentTitle(assembly);
            }
            generator.WriteTypeIndex();
            generator.DocumentTypes();

            // Write markdown to the output file
            File.WriteAllText(outputFileName, generator.Writer.FullText);
        }
Example #3
0
        public static void GenerateMarkdown(
            OrderedTypeList typeList,
            string documentTitle,
            bool showDocumentDateTime,
            bool documentMethodDetails,
            bool msdnLinks,
            string msdnLinkViewParameter,
            IMarkdownWriter markdownWriter)
        {
            // Generate markdown
            var generator = new DocumentationGenerator(markdownWriter, typeList, msdnLinks, msdnLinkViewParameter, documentMethodDetails);

            if (documentTitle != null)
            {
                generator.WriteDocumentTitle(documentTitle);
            }
            if (showDocumentDateTime)
            {
                generator.WritedDateLine();
            }
            generator.WriteTypeIndex();
            generator.WriteDocumentationForTypes();
        }
Example #4
0
        static void Main(string[] args)
        {
            var options = Parse(args);

            if (options == null)
            {
                return;
            }

            var writer = MarkdownWriters.FirstOrDefault(md => md.FormatName.Equals(options.Format, StringComparison.OrdinalIgnoreCase));

            if (options.Format == null)
            {
                writer = MarkdownWriters.First();
                Console.WriteLine($"Markdown format not specified. Assuming {writer.FormatName}.");
            }
            if (writer == null)
            {
                Console.WriteLine($"Error: invalid markdown format specified. Valid values: {MarkdownFormatNames}");
                return;
            }

            try
            {
                if (!File.Exists(options.AssemblyName))
                {
                    throw new FileNotFoundException("File not found", options.AssemblyName);
                }

                var fullAssemblyName = Path.GetFullPath(options.AssemblyName);
                if (options.Verbose)
                {
                    Console.WriteLine($"Document full assembly file name: \"{fullAssemblyName}\"");
                }

                if (options.Verbose)
                {
                    AppDomain.CurrentDomain.AssemblyLoad += ShowAssemblyLoaded;
                }
                AppDomain.CurrentDomain.AssemblyResolve +=
                    (sender, args) => ResolveAssembly(sender, args, options.Verbose, Path.GetDirectoryName(fullAssemblyName));

                var myAssembly = Assembly.LoadFile(fullAssemblyName);
                if (myAssembly == null)
                {
                    throw new Exception($"Could not load assembly \'{options.AssemblyName}\'");
                }

                Type rootType = null;
                if (options.TypeName != null)
                {
                    rootType = myAssembly.DefinedTypes.FirstOrDefault(t => t.Name == options.TypeName);
                    if (rootType == null)
                    {
                        var possibleTypes = myAssembly.DefinedTypes
                                            .Where(t => t.Name.Contains(options.TypeName, StringComparison.OrdinalIgnoreCase))
                                            .Select(t => t.Name).ToList();
                        if (possibleTypes.Count == 0)
                        {
                            throw new Exception(
                                      $"Specified type name \'{options.TypeName}\' not found in assembly \'{options.AssemblyName}\'");
                        }

                        throw new Exception(
                                  $"Specified type name \'{options.TypeName}\' not found in assembly \'{options.AssemblyName}\'." +
                                  $" Similar type names in the assembly: {string.Join(",", possibleTypes)}");
                    }
                }
                var recursive = options.AllRecursive || options.RecursiveAssemblies.Any();
                if (options.AllRecursive)
                {
                    options.RecursiveAssemblies = new List <string>();
                }

                var msdnLinks = !string.IsNullOrEmpty(options.MsdnLinkViewParameter);
                var msdnView  = options.MsdnLinkViewParameter;
                if (msdnLinks && msdnView.Equals("default", StringComparison.OrdinalIgnoreCase))
                {
                    msdnView = null;
                }
                var assembly = rootType == null ? myAssembly : null;
                var typeList = OrderedTypeList.LoadTypes(
                    rootType,
                    assembly,
                    recursive,
                    options.RecursiveAssemblies.ToList(),
                    options.IgnoreAttributes.ToList(),
                    options.IgnoreMethods,
                    options.Verbose);

                DocumentationGenerator.GenerateMarkdown(
                    typeList,
                    GenerateTitle(assembly, options.DocumentTitle),
                    !options.DoNotShowDocumentDateTime,
                    options.DocumentMethodDetails,
                    msdnLinks,
                    msdnView,
                    writer);

                // Write markdown to the output file
                File.WriteAllText(options.OutputFile, writer.FullText);
            }
            catch (BadImageFormatException exc)
            {
                Console.WriteLine($"Error: {exc.Message}");
                Console.WriteLine($"Hresult:{exc.HResult}");
                if (!exc.HelpLink.IsNullOrEmpty())
                {
                    Console.WriteLine($"Help link: {exc.HelpLink}");
                }
                Console.WriteLine($"{exc.StackTrace}");
            }
            catch (Exception exc)
            {
                Console.WriteLine($"Error: {exc.Message}");
                Console.WriteLine($"{exc.StackTrace}");
            }
        }
        public static void GenerateMarkdown(
            Type rootType,
            Assembly assembly,
            bool recursiveAssemblyTraversal,
            List <string> recursiveAssemblies,
            List <string> ignoreAttributes,
            bool ignoreMethods,
            bool msdnLinks,
            string msdnView,
            bool showDateLine,
            bool verbose,
            IMarkdownWriter markdownWriter,
            string outputFileName)
        {
            // Reflection setup
            var allAssemblyTypes = assembly != null;

            if (assembly == null)
            {
                assembly = rootType.Assembly;
            }
            var ignoreAttributesSet = ignoreAttributes == null || ignoreAttributes.Count == 0 ? null : new HashSet <string>(ignoreAttributes);

            if (recursiveAssemblies != null && recursiveAssemblies.Count == 0)
            {
                recursiveAssemblies = null;
            }

            if (verbose)
            {
                if (assembly != null)
                {
                    Log(assembly, "Root assembly ");
                }
            }

            var reflectionSettings = ReflectionSettings.Default;

            reflectionSettings.PropertyFilter = info => PropertyFilter(info, ignoreAttributesSet, verbose);
            reflectionSettings.MethodFilter   = info => MethodFilter(info, ignoreMethods, ignoreAttributesSet, verbose);
            reflectionSettings.TypeFilter     = type => TypeFilter(type, ignoreAttributesSet, verbose);
            reflectionSettings.AssemblyFilter =
                reflectionAssembly => AssemblyFilter(reflectionAssembly, assembly, recursiveAssemblies, recursiveAssemblyTraversal, verbose);

            // Reflection
            var typeCollection = allAssemblyTypes ?
                                 TypeCollection.ForReferencedTypes(assembly, reflectionSettings) :
                                 TypeCollection.ForReferencedTypes(rootType, reflectionSettings);

            // Generate markdown
            var generator = new DocumentationGenerator(markdownWriter, typeCollection, rootType, msdnLinks, msdnView);

            if (assembly != null)
            {
                generator.WriteDocumentTitle(assembly);
            }
            if (showDateLine)
            {
                generator.WritedDateLine();
            }
            generator.WriteTypeIndex();
            generator.DocumentTypes();

            // Write markdown to the output file
            File.WriteAllText(outputFileName, generator.Writer.FullText);
        }