如何打开一个RESX资源文件转换成字典字典、文件转换成、资源、RESX

2023-09-04 03:38:19 作者:与你共江山

我目前工作的一个DLL这将是整个未来的项目中使用,并试图与developped在最后一节的每个有用的方法填充。其中一个方法,我想重复使用可生成excel文件与任何对象集合,并使用RESX资源文件基于对象的属性名称来获取列标题。

I'm currently working on a dll which would be used across future projects, and trying to fill it with every useful method developped in the last one. One of these methods that i'd like to re-use allows to generate an excel file with any object collection, and uses a resx resource file to get the column headers based on the object's property names.

现在,我的问题是,我无法访问,甚至检查从库这样的文件存在。一个可能的解决办法是把这个资源文件到一个字典,并将其作为一个参数,但我没有找到一个方法来做到这一点,或关于这个问题的任何文件。任何提示或建议,这事吗?

Now, my problem is that I can't access or even check the existence of such a file from the library. A possible workaround would be to turn this resource file into a dictionary and pass it as a parameter, but I didn't find a way to do so or any documentation on the subject. Any hint or suggestion about this ?

感谢你帮我在这里...

Thank you for helping me here...

P.S。 :我正在使用Visual Studio 2013,万一这可能是相关的

P.S. : I'm working with Visual Studio 2013, in case that could be relevant.

推荐答案

下面是一个解决方法,我发现,并且允许得到一个RuntimeResourceSet对象,这是结构上接近dictionnary(并可以很容易地变成一体,如果你特别需要一个dictionnary):

Here's a workaround I found and which allows to get a "RuntimeResourceSet" object, which is structurally close to a dictionnary (and which could be easily turned into one, if you specifically need a dictionnary) :

var myResourceSet = MyResource.ResourceManager.GetResourceSet(CultureInfo.CurrentCulture, true, true);

然后,就可以得到一组的项目是这样的:

Then, you can get the set's items this way :

var myString = myResourceSet.GetString("MyKey");

希望这将有助于!

Hope that will help !

 
精彩推荐
图片推荐