阅读在C#中的文件编译时 [英] Read a file compile-time in C#

查看:136
本文介绍了阅读在C#中的文件编译时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写的,我需要一个假的XML文件一些单元测试。我可以创建文件,并要求其与单元测试进行部​​署,但经验表明,在我的办公室它的很多头痛。所以我决定,该文件将被UT的创建

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 office it's a lot of headache. So I decided that the file will be created by UT's.

StreamWriter sw = new StreamWriter(testFileName);
sw.Write(contents);
sw.Close();

现在的问题是内容的字符串。这几乎是一个漫长的XML,像这样:

Now the problem is the contents string. It is virtually a long xml, something like this:

string contents = 
@"<?xml version="1.0" encoding="windows-1251"?>
  <blah>
  ~100 lines here
  </blah> ";



我不希望这是在同一个文件中的代码的其余部分。我想生成字符串从一个文件的编译时间。

I don't want this to be in the same file as the rest of the code. I want the string to be generated compile-time from a file.

在C ++中,我会做到这一点。

In C++, I'd do this

string contents = "
#include "test.xml"
   ";

是否有可能以某种方式在C#中?

Is it possible somehow in C#?

推荐答案

你为什么不包括在资源?

Why don't you include it in a resource?

这篇关于阅读在C#中的文件编译时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆