Read a file compile-time in C#

前端 未结 6 1271
攒了一身酷
攒了一身酷 2021-01-05 13:37

I am writing some unit tests in which I need a fake xml file. I can create that file and require it to be deployed with the unit tests, but experience shows that at my offic

6条回答
  •  再見小時候
    2021-01-05 14:36

    You can go the resource file route but, depending on how many resources/how large they are (and XML can be large), you may eventually run into compilation problems (I did).

    I've since transitioned from resources to singletons. Reading a text file in with File.ReadAllText is pretty dead simple and it's still IntelliSense-friendly.

提交回复
热议问题