Click here to Skip to main content
15,884,177 members
Articles / Programming Languages / Visual Basic

VS.NET CodeDOM-Based Custom Tool for String Resource Management

Rate me:
Please Sign up or sign in to vote.
4.52/5 (12 votes)
22 Jun 200413 min read 123.4K   1.1K   48  
A VS.NET custom tool, created with the help of CodeDOM and EnvDTE, used to facilitate management of resource strings via IntelliSense and error checking in VS.NET environment.
'------------------------------------------------------------------------------
' <autogenerated>
'     This code was generated by a tool.
'     Runtime Version: 1.1.4322.573
'
'     Changes to this file may cause incorrect behavior and will be lost if 
'     the code is regenerated.
' </autogenerated>
'------------------------------------------------------------------------------

Option Strict On
Option Explicit On

Imports System
Imports System.Reflection
Imports System.Resources


'-----------------------------------------------------------------------------
' <autogeneratedinfo>
'     This code was generated by:
'       ResourceClassGenerator custom tool for VS.NET
'
'     It contains classes defined from the contents of the resource file:
'       C:\Development\DotNet\Essential Tools\ResourceClassGenerator\TestVB\Resources\Strings.en.resx
'
'     Generated: Wednesday, June 23, 2004 10:22 AM
' </autogeneratedinfo>
'-----------------------------------------------------------------------------
Namespace Resources.Strings
    
    '<summary>
    'Provides access to an assembly's string resources
    '</summary>
    Class ResourceFormatter
        
        Private Shared _ResourceManager As System.Resources.ResourceManager
        
        '<summary>
        'ResourceManager property with lazy initialization
        '</summary>
        '<value>An instance of the ResourceManager class.</value>
        Private Shared ReadOnly Property ResourceManager As System.Resources.ResourceManager
            Get
                If (_ResourceManager Is Nothing) Then
                    _ResourceManager = New System.Resources.ResourceManager("TestVB.Strings", System.Reflection.Assembly.GetExecutingAssembly)
                End If
                Return _ResourceManager
            End Get
        End Property
        
        '<summary>
        'Loads an unformatted string
        '</summary>
        '<param name="resourceId">Identifier of string resource</param>
        '<returns>string</returns>
        Public Overloads Shared Function GetString(ByVal resourceId As String) As String
            Return ResourceFormatter.ResourceManager.GetString(resourceId)
        End Function
        
        '<summary>
        'Loads a formatted string
        '</summary>
        '<param name="resourceId">Identifier of string resource</param>
        '<param name="objects">Array of objects to be passed to string.Format</param>
        '<returns>string</returns>
        Public Overloads Shared Function GetString(ByVal resourceId As String, ByVal args() As Object) As String
            Dim format As String = ResourceFormatter.ResourceManager.GetString(resourceId)
            Return String.Format(format, args)
        End Function
    End Class
    
    '<summary>
    'Access to resource identifier Label1
    '</summary>
    Class Label1
        
        Public Shared Function GetString() As String
            Return ResourceFormatter.GetString("Label1")
        End Function
    End Class
    
    '<summary>
    'Access to resource identifier Label2
    '</summary>
    Class Label2
        
        Public Shared Function GetString(ByVal arg0 As Object, ByVal arg1 As Object) As String
            Return ResourceFormatter.GetString("Label2", New Object() {arg0, arg1})
        End Function
    End Class
    
    '<summary>
    'Access to resource identifier Label3
    '</summary>
    Class Label3
        
        Public Shared Function GetString() As String
            Return ResourceFormatter.GetString("Label3")
        End Function
    End Class
    
    '<summary>
    'Access to resource identifier Label4
    '</summary>
    Class Label4
        
        Public Shared Function GetString() As String
            Return ResourceFormatter.GetString("Label4")
        End Function
    End Class
    
    '<summary>
    'Access to resource identifier Label5
    '</summary>
    Class Label5
        
        Public Shared Function GetString() As String
            Return ResourceFormatter.GetString("Label5")
        End Function
    End Class
End Namespace

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Software Developer Mono Ltd
Croatia Croatia
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions