/// <inheritdoc/>
        public void WriteNamespaceDocument(NamespaceInfo nameSpace, IClassDocumentFormatter formatter)
        {
            string filePath = GetNamespaceDocumentFilePath(nameSpace, false);

            if (!NamespaceDocumentTemplateState.IsCompiled)
            {
                NamespaceDocumentTemplateState.Compile(typeof(NamespaceInfo));
            }

            WriteDocument(nameSpace, filePath, Settings.NamespaceDodumentSettings?.Encoding, NamespaceDocumentTemplateState.Key, formatter);
        }
        /// <inheritdoc/>
        public void WriteTypeDocument(TypeWithComment type, IClassDocumentFormatter formatter)
        {
            string filePath = GetTypeDocumentFilePath(type, false);

            if (!TypeDocumentTemplateState.IsCompiled)
            {
                TypeDocumentTemplateState.Compile(typeof(TypeWithComment));
            }

            WriteDocument(type, filePath, Settings.TypeDodumentSettings?.Encoding, TypeDocumentTemplateState.Key, formatter);
        }
Example #3
0
        /// <inheritdoc/>
        public void WriteTypeDocument(TypeWithComment type, IClassDocumentFormatter formatter)
        {
            string filePath = GetTypeDocumentFilePath(type, false);
            string dir      = Path.GetDirectoryName(filePath);

            if (!Directory.Exists(dir))
            {
                Directory.CreateDirectory(dir);
            }

            RazorEngine.Templating.DynamicViewBag viewBag = new RazorEngine.Templating.DynamicViewBag();
            viewBag.AddValue("Formatter", formatter);

            if (!TypeDocumentTemplateState.IsCompiled)
            {
                TypeDocumentTemplateState.Compile(typeof(TypeWithComment));
            }

            using (StreamWriter writer = new StreamWriter(filePath, false, Settings.TypeDodumentSettings.Encoding))
            {
                Engine.Run(TypeDocumentTemplateState.Key, writer, type.GetType(), type, viewBag: viewBag);
                writer.Flush();
            }
        }
Example #4
0
        /// <summary>
        /// Create a default settings.
        /// </summary>
        /// <param name="encoding">The output document encoding.</param>
        /// <param name="rootDirectory">The path of the root directory of the output destination.</param>
        /// <param name="documentFormatter">The document formatter.</param>
        /// <param name="namespaceDocumentTemplate">The Razor template for the namespace document.</param>
        /// <param name="typeDocumentTemplate">The Razor template for the type document.</param>
        /// <returns></returns>
        public static RazorDocumentWriterSettings CreateDefaultSettings(Encoding encoding, string rootDirectory, IClassDocumentFormatter documentFormatter, string namespaceDocumentTemplate, string typeDocumentTemplate)
        {
            return(new RazorDocumentWriterSettings()
            {
                RootDirectory = rootDirectory,

                NamespaceDodumentSettings = new RazorDocumentSettings <NamespaceInfo>()
                {
                    Encoding = encoding,
                    DocumentFormatter = documentFormatter,
                    Template = namespaceDocumentTemplate
                },

                TypeDodumentSettings = new RazorDocumentSettings <TypeWithComment>
                {
                    Encoding = encoding,
                    DocumentFormatter = documentFormatter,
                    Template = typeDocumentTemplate
                }
            });
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="model"></param>
        /// <param name="filePath"></param>
        /// <param name="encoding"></param>
        /// <param name="templateKey"></param>
        /// <param name="formatter"></param>
        private void WriteDocument <T>(T model, string filePath, Encoding?encoding, ITemplateKey templateKey, IClassDocumentFormatter formatter)
        {
            string dir = Path.GetDirectoryName(filePath);

            if (!Directory.Exists(dir))
            {
                Directory.CreateDirectory(dir);
            }

            RazorEngine.Templating.DynamicViewBag viewBag = new RazorEngine.Templating.DynamicViewBag();
            viewBag.AddValue("Formatter", formatter);

            using StreamWriter writer = new StreamWriter(filePath, false, encoding ?? Encoding.UTF8);

            Engine.Run(templateKey, writer, typeof(T), model, viewBag: viewBag);

            writer.Flush();
        }