.NET Resource Management Classes

I l @ ve RuBoard

The .NET framework provides a family of classes that are designed to make resource management consistent and easy. These classes are as follows :

  • ResourceManager is used to manage all resources in an application.

  • ResourceSet represents a collection of all the resources for a particular culture.

  • ResourceReader is an implementation class for the IResourceReader interface. This is used to read resources from a stream.

  • ResourceWriter is an implementation of the IResourceWriter interface. This are used to write resources to a stream.

Your application must use a ResourceManager to load the resource assemblies and make them available to the rest of the program. The ResourceManager will return a ResourceSet for a given culture.

Got Culture?

Different cultures and languages are identified through the CultureInfo class. This class is a simple information store that contains data about the culture selected by the user when he or she installed the operating system. It contains information about the language, calendar, currency, and other preferences that the user might have chosen . Your software will have access to this information so that it can determine whether it has the ability to offer culture-specific resources or must choose the neutral default value.

Being culture specific might be very important in the message you are trying to deliver. There is an anecdote that illustrates why.

A Little Bit of Culture

A large soap manufacturer created a printed advertisement for display on billboards that showed dirty clothes being loaded into a washing machine. A second picture showed the washing powder being poured into the machine and a third image depicted these clothes being taken out of the washer all clean and fresh. They couldn't understand why the sales of the product dropped dramatically in certain countries until it was pointed out that the places that had low sales were right-to-left reading cultures. Their advertisement, created by American's, had shown clean clothes washed in this soap powder emerging all dirty and stained from the machine. Never underestimate the power of assumption.

Culture information about languages is provided by a two-letter code and an optional region identifier that accompanies the two letter code. For example, the neutral English language is represented by the two letter code en , but the different flavors of English ”English from England, Canada, the United States and other places ”is identified by the sub-codes GB , CA , US , and so on.

Listing 3.4.1 shows a program that will get the CultureInfo for your computer and display the language and region that applies to your computer. It also shows the full name of the culture and which calendar your current culture is using.

Listing 3.4.1 culture.cs: Displaying the Current Culture Information
 1: namespace Sams  2: {  3:    using System;  4:    using System.Drawing;  5:    using System.Collections;  6:    using System.ComponentModel;  7:    using System.Globalization;  8:    using System.Windows.Forms;  9:    using System.Data; 10: 11: class CultureInfoTest : Form 12: { 13: 14:    public CultureInfoTest() 15:    { 16:       this.Size = new Size(300,200); 17: 18:       Label l = new Label(); 19:       l.Location = new Point(3,5); 20:       l.Size = new Size(294,190); 21: 22:       InputLanguage inL = InputLanguage.CurrentInputLanguage; 23: 24:       CultureInfo info = inL.Culture; 25: 26:       l.Text = String.Format("Culture identifier = { 0} \ n"+ 27:                   "Display name = { 1} \ n"+ 28:                   "Calender = { 2} \ n", 29:                   info.ToString(), 30:                   info.DisplayName, 31:                   info.Calendar.ToString()); 32:       this.Controls.Add(l); 33: 34:    } 35:    static void Main() 36:    { 37:       Application.Run(new CultureInfoTest()); 38:    } 39: } 40: 41: } 
I l @ ve RuBoard


C# and the .NET Framework. The C++ Perspective
C# and the .NET Framework
ISBN: 067232153X
EAN: 2147483647
Year: 2001
Pages: 204

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net