Пример #1
0
        /// <summary>
        ///   Writes the source code information in this object out to a file in the form of source code.
        /// </summary>
        /// <param name="rootFolder">Root location of the file. (The relative path will be added to this folder to generate the file.)</param>
        /// <exception cref="ArgumentNullException"><paramref name="rootFolder"/> is a null reference.</exception>
        /// <exception cref="ArgumentException"><paramref name="rootFolder"/> is not a valid folder path.</exception>
        /// <exception cref="IOException">An error occurred while writing to the file.</exception>
        public void WriteToFile(string rootFolder, bool uppercaseFileName = true)
        {
            if (rootFolder == null)
            {
                throw new ArgumentNullException("rootFolder");
            }
            if (rootFolder.Length == 0)
            {
                throw new ArgumentException("rootFolder is an empty string");
            }
            try
            {
                rootFolder = Path.GetFullPath(rootFolder);
            }
            catch (Exception e)
            {
                throw new ArgumentException("rootFolder is not a valid path (see inner exception).", e);
            }

            string fullFolderPath;

            if (RelativePath.Length > 0)
            {
                fullFolderPath = Path.Combine(rootFolder, RelativePath);
            }
            else
            {
                fullFolderPath = rootFolder;
            }
            string fileName = FileName;

            if (!uppercaseFileName)
            {
                fileName = FileName.ToLower();
            }
            string fullPath = Path.Combine(fullFolderPath, fileName);

            // Generate any needed directories.
            DefaultValues.CreateFolderPath(fullFolderPath);
            using (StreamWriter wr = new StreamWriter(fullPath))
            {
                DocumentationHelper.WriteFileHeader(wr, fileName, Description);

                if (DefaultValues.IncludeSubHeader)
                {
                    WriteFileSubHeader(wr);
                }

                // Add usings.
                string[] usings = Module.Usings;
                if (usings.Length > 0)
                {
                    Dictionary <string, List <string> > lookup = GetLibraryLookup();
                    foreach (string key in lookup.Keys)
                    {
                        DocumentationHelper.WriteLine(wr, string.Format("library {0};", key), 0);
                        foreach (string use in lookup[key])
                        {
                            DocumentationHelper.WriteLine(wr, string.Format("use {0};", use), 0);
                        }
                        DocumentationHelper.WriteLine(wr);
                    }
                }

                Module.Write(wr, 0);
            }
        }