40.5. Coding Resource Files

In addition to the rich visual tools that Visual Studio 2008 now provides for editing resource files, it is possible to use code to create resource files. The .NET Framework provides support for reading and writing resource files using two interfaces: IResourceReader and IResourceWriter. Once the resource files have been created, they need to be added to the application or manually linked so that they can be referenced within the application.

  • IResource Reader: The reader interface ensures that resource readers have the following methods:

    • GetEnumerator: The GetEnumerator method retrieves an IDictionaryEnumerator object that permits the developer to iterate over each of the resources in the resource file.

    • Close: The Close method is used to close the resource reader and release any associated resources.

  • IResource Writer: The writer interface ensures that resource writers have the following methods:

    • AddResource: There are three overloads to the AddResource method that support adding resources to the resource file. Both of the framework implementations of this interface have either an additional overload of this method or an alternative method for adding resources. The overloads that are part of this interface support adding resources in a name-value pair. Each method has the resource name as the first parameter and a value, such as a string, byte array, or object, as the second parameter. The final implementation that takes an object as a parameter may need ...

Get Professional Visual Studio® 2008 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.