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
        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}");
            }
        }