4

これは奇妙な質問のように思えるかもしれませんが、コードをpdfに変換する必要があります。そうすれば、コードを渡すことができます。残念ながら、学校のシステムでは、CDのコードをpdfとして要求しています。私にできることは、ソリューション内のすべてのクラスを開いて、コピーして貼り付けることです。しかし、プログラマーとして、私は怠け者であり、Visual Studioにこのための機能があるかどうか知りたいですか?または他の方法がありますか?

編集:フォルダ内のすべてのファイルを反復処理し、ファイルを開いてその内容をpdfファイルにコピーするサードパーティのプログラム。同様に機能します-VisualStudio内にある必要はありません。

4

1 に答える 1

1

待つのにうんざりしたので、私が思いついたのは次のとおりです。

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;

namespace GetFileContents
{
    class Program
    {
        static string types = ".js,.cshtml,.cs,.less,.css";
        private static string text = "";
        static void Main(string[] args)
        {
            //This folder wraps the whole thing.
            string folderPath = @"C:\randomFolderWhereProjectIs\";

            string s = IterateIt(Directory.GetDirectories(folderPath).ToList());
            //Save to file or whatever I just used the text visualiser in Visual Studio
        }

        private static string IterateIt(List<string> l)
        {

            foreach (var path in l)
            {
                var files = Directory.GetFiles(path).Select(c => new FileInfo(c)).Where(c => types.Split(',').Contains(c.Extension));

                foreach (var fileInfo in files)
                {
                    text += fileInfo.Name + "\r\n";
                    using (StreamReader reader = fileInfo.OpenText())
                    {
                        text += reader.ReadToEnd() + "\r\n";
                    }
                }
                text = IterateIt(Directory.GetDirectories(path).ToList());
            }
            return text;
        }


    }
}
于 2012-05-30T12:32:02.173 に答える