Click here to Skip to main content
15,896,111 members
Articles / Web Development / ASP.NET

Customize the Code Generated by the Resources Designer

Rate me:
Please Sign up or sign in to vote.
3.83/5 (6 votes)
19 Dec 2008CPOL8 min read 47.2K   970   38  
Customize the code generated by the resources designer
Imports System
Imports Generators = Kodeo.Reegenerator.Generators
Imports Wrappers = Kodeo.Reegenerator.Wrappers

Namespace Scenario1
    ''' <summary>
    ''' SmallChangesToDefaultResX custom generator class.
    ''' </summary>
    Public Class SmallChangesToDefaultResX
        Inherits Generators.CodeRenderer
        ''' <summary>
        ''' Default custom tool name for resx files.
        ''' </summary>
        Public Const CustomToolName As String = "ResXFileCodeGenerator"
        ''' <summary>
        ''' Renders the code.
        ''' </summary>
        ''' <returns>A <see cref="Generators.RenderResults"/> that contains the content of the generated files.</returns>
        Public Overrides Function Render() As Generators.RenderResults
            ' execute the default custom tool.
            Dim ctResults As Byte() = MyBase.RunOtherCustomTool(CustomToolName)
            ' get Microsoft's generated code as string.
            Dim results As String = System.Text.Encoding.Default.GetString(ctResults)

            Dim preamble As String = System.Text.Encoding.Default.GetString(System.Text.Encoding.UTF8.GetPreamble())
            If results.StartsWith(preamble) Then
                results = results.Substring(preamble.Length)
            End If

            ' transform the string.
            Dim modifiedResults As String = AddSomething(results)
            ' return the string to be saved into the .Designer.cs file.
            Return New Generators.RenderResults(modifiedResults)
        End Function

        Private Function AddSomething(ByVal results As String) As String
            results = String.Format( _
    "' -------------------------------------------------------" & Environment.NewLine & _
    "' Automatically generated with Kodeo's Reegenerator" & Environment.NewLine & _
    "' Generation date: {0}" & Environment.NewLine & _
    "' Generated by: {1}" & Environment.NewLine & _
    "' -------------------------------------------------------" & Environment.NewLine & _
    "{2}", _
                       System.DateTime.Now.ToString("yyyy-MM-dd hh:mm"), _
                       System.Security.Principal.WindowsIdentity.GetCurrent().Name, _
                       results)
            Return results
        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, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Architect
New Zealand New Zealand
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions