开发者

Returning Resources Based on a Key

开发者 https://www.devze.com 2023-04-10 08:14 出处:网络
Based on my previous question, it looks like emedded resources are not going to work in my project. So pla开发者_Go百科n #2 is to use regular resources via a resx file.

Based on my previous question, it looks like emedded resources are not going to work in my project. So pla开发者_Go百科n #2 is to use regular resources via a resx file.

The core of my question is: is it possible to write a function that will take a string key, and return that resource? I tried this with reflection, but I couldn't get it to work.

Here's a sample of how I would like it to work. Let's say I have a Resources.resx file, which has two file resources: MainMap and OverWorld. I would like to write the function that works like:

string mainMapContent = getFromResources("MainMap"); // => returns Resources.MainMap
string overWorldCOntent = getFromResoures("OverWOrld"); // => returns Resources.OverWorld

I tried using reflection to create an instance of the Resources class, but bailed out when I realized the constructor is internal and there's no empty constructor I can use.

Is there a way to write this getFromResources function? I can't figure it out.

Note: I will probably put this into a library if I can do it; it needs to work with the Silverlight runtime, too.


The strongly typed resource class that is generated through code-generation is based on the untyped ResourceManager class. You should be able to use ResourceManager.GetObject

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号