C# 使用字符串获取资源

C# 使用字符串获取资源,c#,C#,我在参考资料文件夹中有很多txt文件。其中之一是corner.txt。我可以通过以下代码段访问此文件: Properties.Resources.corner string st = Properties.Resources.ResourceManager.GetString(tableName); 我将文件名保存在字符串变量中。例如: string fileName = "corner.txt"; 我想通过以下方式访问此文件: Properties.Resources.fileName

我在参考资料文件夹中有很多txt文件。其中之一是corner.txt。我可以通过以下代码段访问此文件:

Properties.Resources.corner
string st = Properties.Resources.ResourceManager.GetString(tableName);
我将文件名保存在字符串变量中。例如:

string fileName = "corner.txt";
我想通过以下方式访问此文件:

Properties.Resources.fileName 
这可能吗?如何访问?

您可以这样使用:

var type = typeof(Properties.Resources);
var property = type.GetProperty(fileName, BindingFlags.Static| BindingFlags.NonPublic|BindingFlags.Public);
var value = property.GetValue(null, null);
value = Properties.Resources.ResourceManager.GetObject(fileName, Properties.Resources.Culture);
或者像这样使用
ResourceManager

var type = typeof(Properties.Resources);
var property = type.GetProperty(fileName, BindingFlags.Static| BindingFlags.NonPublic|BindingFlags.Public);
var value = property.GetValue(null, null);
value = Properties.Resources.ResourceManager.GetObject(fileName, Properties.Resources.Culture);

我通过以下代码片段解决了这个问题:

Properties.Resources.corner
string st = Properties.Resources.ResourceManager.GetString(tableName);
所以,我不使用文件名,而是使用txt文件的字符串。这对我很有用


非常感谢。

完全不清楚你在问什么。文件名在哪里?它是生成的资产吗?它是您在某个完全不关联的类中声明的局部变量吗?什么?重复:将文本设置为粗体并不能澄清您的要求。文件名是完整路径还是仅为文件名?或者它是你想要访问的一个类?可能是我没有得到它的副本。请您提供一些更详细的信息,好吗?他想通过字符串资源条目名称而不是intellisense属性来访问资源。