.NET Framework CLR Tools: How do I use the Resource File Generator?
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 1 of 1

Thread: .NET Framework CLR Tools: How do I use the Resource File Generator?

  1. #1
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,097

    .NET Framework CLR Tools: How do I use the Resource File Generator?

    Q: How do I use the Resource File Generator?

    A: The Resource File Generator converts '.txt' files and '.resx' (XML-based resource format) files to common language runtime binary '.resources' files that can be embedded in a runtime binary executable or compiled into satellite assemblies.


    • What conversions does the 'rResGen.exe' tool perform?

      'Resgen.exe' performs the following conversions:


      • Converts '.txt' files to '.resources' or '.resx' files.
      • Converts '.resources' files to text or '.resx' files.
      • Converts '.resx' files to '.txt' or '.resources' files




    • What classes does the resource generator use?


      • 'ResourceReader' class
      • 'ResourceWriter' class
      • 'ResXResourceReader' class
      • 'ResXResourceWriter' class




    • What does the 'ResourceReader' class do?


      • The 'ResourceReader' provides a default implementation of the 'IResourceReader' interface.

      • You can use resource readers to read resource name and resource value pairs from '.resources' files.

      • The resources can be enumerated by traversing the 'IDictionaryEnumerator' returned by the 'GetEnumerator()' method.

      • The methods provided by the 'IDictionaryEnumerator' are used to advance to the next resource and read the name and value of each resource in the '.resources' file.




    • Can I have an example using the 'ResourceReader' class?

      The following code sample displays the content of 'myResources.resources' file on the console:


      Code:
      Imports System
      Imports System.Resources
      Imports System.Collections
      
      Public Class ReadResources
          
          Public Shared Sub Main()
              
              ' Opens a resource reader and get an enumerator from it.
              Dim reader As New ResourceReader("myResources.resources")
              Dim en As IDictionaryEnumerator = reader.GetEnumerator()
              
              ' Goes through the enumerator, printing out the key and value pairs.
              While en.MoveNext()
                  Console.WriteLine()
                  Console.WriteLine("Name: {0}", en.Key)
                  Console.WriteLine("Value: {0}", en.Value)
              End While
              reader.Close()
              
          End Sub
      End Class

    • What does the 'ResourceWriter' class do?

      Writes resources in the system-default format to an output file or an output stream.



    • Can I have an example using the 'ResourceWriter' class?

      The following example writes several strings into the 'myResources.resources' file:


      Code:
      Imports System
      Imports System.Resources
      
      Public Class WriteResources
          
          Public Shared Sub Main()
              
              ' Creates a resource writer.
              Dim writer As New ResourceWriter("myResources.resources")
              
              ' Adds resources to the resource writer.
              writer.AddResource("String 1", "First String")
              
              writer.AddResource("String 2", "Second String")
              
              writer.AddResource("String 3", "Third String")
              
              [COLOR=#880000]' Writes the resources to the file or stream, and closes it.
              writer.Close()
          End Sub
      End Class

    • What does the 'ResXResourceReader' do?


      • You can use resource readers to read resource name and value pairs from '.resx' files.
      • The resources can be enumerated by traversing the 'IDictionaryEnumerator' returned by the 'GetEnumerator()' method.
      • You can use the methods provided by the 'IDictionaryEnumerator' to advance to the next resource and read the name and value of each resource in the '.resx' file.




    • Can I have an example using the 'ResXResourceReader' class?

      The following example demonstrates how to use a 'ResXResourceReader' to iterate through the resources in a '.resx' file. First, the


      Code:
      ResXResourceReader rsxr
      is created for the file 'items.resx'. Next, the 'GetEnumerator()' method is used to create an 'IDictionaryEnumerator' to iterate through the resources and display the contents to the console:


      Code:
      Imports System
      Imports System.Resources
      Imports System.Collections
      Imports Microsoft.VisualBasic
      
      Class ReadResXResources
         
         Public Shared Sub Main()
            
            ' Create a ResXResourceReader for the file items.resx.
            Dim rsxr As ResXResourceReader
            rsxr = New ResXResourceReader("items.resx")
      
            ' Create an IDictionaryEnumerator to iterate through the resources.
            Dim id As IDictionaryEnumerator = rsxr.GetEnumerator()
                  
            ' Iterate through the resources and display the contents to the console.
            Dim d As DictionaryEntry
            For Each d In  rsxr
               Console.WriteLine(d.Key.ToString() + ":" + ControlChars.Tab + d.Value.ToString())
            Next d
            
            'Close the reader.
            rsxr.Close()
      
         End Sub
      
      End Class

    • What does the 'ResXResourceWriter' class do?

      Writes resources in an XML resource ('.resx') file or an output stream.



    • How do I use the 'ResGen' tool?

      You run the 'Resgen.exe' tool from the command prompt:

      Code:
      resgen [/compile] filename.extension [outputFilename.extension][...]

    • Can I have a few examples using the 'ResGen.exe' tool?


      • The following command reads the name/value pairs in 'myResources.txt' and writes a binary resources file named 'yourResources.resources.':


        Code:
        resgen myResources.txt yourResources.resources
      • The following command reads an XML-based input file 'myResources.resx' and writes a binary resources file named 'myResources.resources':


        Code:
        resgen myResources.resx myResources.resources
      • The following command reads a binary resources file 'myResources.resources' and writes an XML-based output file named 'myResources.resx':


        Code:
        resgen myResources.resources myResources.resx



    Last edited by Andreas Masur; December 22nd, 2005 at 06:02 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center