Resource File Wrapper (Generator)

In order to write code that uses resources that reside in resource files, I wrote a wrapper class (you know a class that would have a strongly typed property for each resource in the resource file) ... and then I wrote a little application to generate that wrapper. You can now Read the details or download the code The classes are generated using XSLT templates that are included with the dll project in the download - so you can tweak them as you see fit.

It will generate a wrapper in VB.Net, C# or managed C++.... yea thats right managed C++.  Using the wrapper class it will allow you to write code like this


  120
         Images imageResource = new Images();

  121         _pbImage.Image = imageResource.DiscoveryPark5;

 

Instead of code like this:


  120
         Assembly assembly = Assembly.GetExecutingAssembly();

  121         ResourceManager resources = new ResourceManager("HenleyCSharp.Images", assembly);

  122         _pbImage.Image = (Image)resources.GetObject(DISCOVERYPARK5);

 

BTW: any of you C++ (or VB and C#) folks that download the code an find anything wrong with the generated code, please let me know.  The templates were designed to create a wrapper that works with the sample applications in my resource files article (not done yet) ... of which I have C#, C++ and VB.Net versions.

posted on Sunday, November 14, 2004 2:04 PM

Feedback

# re: Resource File Wrapper (Generator)

Nice work! Does this support getting the string out of any satellite assembly with no code changes? Do you need to pass any culture object or does .NET take care of the details?

Thanks,
Derek
11/17/2004 6:17 AM | Derek Price

# re: Resource File Wrapper (Generator)

Derek,

Great idea!

Currently I don't think it does. I will test it and see, if it doesn't I'll try and add it this weekend.

j
11/17/2004 7:27 AM | Jason Haley

# re: Resource File Wrapper (Generator)

Hi,

i followed the steps as specified in the artical but i am still getting the problem. I am getting the bellow mentioned error. Basically i am working on a component 'i18N' the client who uses this i18N dll must be able to get the specified image. please help me out on this problem.

ERROR:
Could not find any resources appropriate for the specified culture (or the neutral culture) in the given assembly. Make sure "i18NSample.one.resources" was correctly embedded or linked into assembly "i18NSample". baseName: i18NSample.one locationInfo: <null> resource file name: i18NSample.one.resources assembly: i18NSample, Version=1.0.1911.29940, Culture=neutral, PublicKeyToken=null


Expecting ur +ve response.

ThanQ
madhu_komminane@india.com
3/25/2005 10:21 PM | Madhusudhana K

# re: Resource File Wrapper (Generator)

It look like your problem might be that the dll you are creating is i18NSample.one.dll or has the default namespace of i18Sample.one, which then causing the assembly to look for a resource at that location. Your best bet is to open the dll with Reflector or ILDasm and see what the real path is to the resource and make sure the constant declared in the wrapper class matches that name. If you read the full article at: http://www.jasonhaley.com/articles/resourcefiles/Resource%20Files.htm it should help you out.
3/25/2005 10:57 PM | Jason Haley

Post Comment

Title  
Name  
Url
Comment   
Please enter the following code into the box below to stop spammers

  
Enter Code Here *