We pay for user submitted tutorials and articles that we publish. Anyone can send in a contributionLearn More
It is very common to use resource files in .Net applications when you need to store some data in a XML file. I usually use .resx files as string tables in order to avoid hard coded strings in my code. Two months ago, we published a post about a free tool which helps to extract hard coded strings to resource files. Notice that when you add a resource file, there is an automatically generated class with properties issued from the resources elements, so you can call this class properties instead of using the ResourceManager. The only problem with this class is that its properties are marked as internal and thus can’t be accessed externally (from other assemblies).
Sometimes you want to gather all of the strings in one central assembly because the same string might be used several times by different code components. Think about localization, you want to have one assembly where all of the messages to the user are located. If you try to use those string tables from other assemblies, you will fail because of the internal keyword. Fortunately, there is a way to instruct the generation process to build a public class with public properties:
Visual Studio 2008: Very easy process, just open the resource editor and change the value in the Access Modifier drop down menu from Internal to Public.
Visual Studio 2005: There is a free custom tool for that purpose called ResXFilePublicCodeGenerator - Download and install it. After the installation, open the properties window of the resource file and change the Custom Tool to ResXFilePublicCodeGenerator, than right click on the resource file and choose the Run Custom Tool from the drop down menu.
That is it, Do you know other ways to do the job? If so, leave your comment…
Tags :.NetassemblyClassgenerateinternalPropertiesPublicResource fileResXFilePublicCodeGeneratorstring tablestringtable
Copyright © 2012 Dev102.com
Breeze : Designed by Amit Raz and Nitzan Kupererd