StronglyTypedResourceBuilder Class

Provides support for strongly-typed resources. This class cannot be inherited.

Namespace:  System.Resources.Tools
Assembly:  System.Design (in System.Design.dll)

public static class StronglyTypedResourceBuilder

The .NET Framework version 2.0 supports strongly-typed resources. Strongly-typed resource support is a compile-time feature that encapsulates access to resources by creating classes that contain a set of static, read-only (get) properties. This provides an alternative way to consume resources, rather than using the GetString and GetObject methods of the ResourceManager class.

Typically, resources separate code from content within an application. Creating and consuming these resources makes it easier to develop localizable applications.

In the .NET Framework, after the resources are created, they are usually consumed by using the ResourceManager class, which contains methods that provide access to culture-specific resources at run time. For more information about these processes, see Resources in Applications.

Strongly-typed resource support is an alternative to using the ResourceManager class to consume resources. The basic functionality is provided by the StronglyTypedResourceBuilder class (as well as a corresponding command-line option in the Resource File Generator (Resgen.exe)). The output of the Create method is a class that contains strongly-typed properties that match the resources that are referenced in the input parameter. This class provides strongly-typed, read-only access to the resources that are available in the file processed.

The following code example generates a class that is written in C#, is in the DemoApp namespace, is named DemoResources, and has properties that return the bitmap of a logo and the name of an application. The code example uses the following file, named demo.resx:

<data name="Logo" type="System.Drawing.Bitmap, System.Drawing, Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base 64 encoded value omitted here]
</value>
</data>
<data name="MyAppTitle">
<value>Demo Application</value>
</data>

Call the Create method with the following arguments:

StronglyTypedResourceBuilder.Create("demo.resx", "DemoResources", "DemoApp", new CSharpCodeProvider(), false, out errors[]) 

The Create method generates the following code:

using System;
using System.IO;
using System.Resources;

namespace DemoApp
{
public class DemoResources
{
protected static ResourceManager rm = new ResourceManager(typeof(className));
public static System.Resources.ResourceManager resourceManager 
{ 
get { return rm; }
}
public static System.Drawing.Bitmap Logo
{
get { return (System.Drawing.Bitmap)rm.GetObject("logo"); }
}
    public static string MyAppTitle
    {
      get { return rm.GetString("MyAppTitle"); }
    }
}
}

In your application code, you can then use the class as follows:

this.Text = DemoResources.MyAppTitle;
System.Drawing.Bitmap bmp = DemoResources.Logo;

System.Object
  System.Resources.Tools.StronglyTypedResourceBuilder

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0, 2.0
Was this page helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft