15.02.2015 Views

C# 4 and .NET 4

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

602 ❘ ChaPTer 22 lOcAlizAtiOn<br />

Because the sysglobl assembly is not in the .<strong>NET</strong> Framework 4 Client Profi le, you<br />

have to set the Target Framework with the project settings for .<strong>NET</strong> Framework 4 to<br />

reference it.<br />

With the constructor of the class CultureAndRegionInfoBuilder , you can pass the culture ’ s name. The<br />

second argument of the constructor requires an enumeration of type CultureAndRegionModifiers .<br />

This enumeration allows one of three values: Neutral for a neutral culture, Replacement if an existing<br />

Framework culture should be replaced, or None .<br />

After the CultureAndRegionInfoBuilder object is instantiated, you can confi gure the culture by setting<br />

properties. With the properties of this class, you can defi ne all the cultural <strong>and</strong> regional information<br />

such as name, calendar, number format, metric information, <strong>and</strong> so on. If the culture should be<br />

based on existing cultures <strong>and</strong> regions, you can set the properties of the instance using the methods<br />

LoadDataFromCultureInfo() <strong>and</strong> LoadDataFromRegionInfo() , <strong>and</strong> change the values that are different<br />

by setting the properties afterward.<br />

Calling the method Register() registers the new culture with the operating system. Indeed, you can fi nd<br />

the fi le that describes the culture in the directory Globalization \ indows> w <<br />

. Look for fi les with the<br />

extension .nlp.<br />

using System;<br />

using System.Globalization;<br />

namespace CustomCultures<br />

{<br />

class Program<br />

{<br />

static void Main()<br />

{<br />

try<br />

{<br />

// Create a Styria culture<br />

var styria = new CultureAndRegionInfoBuilder("de-AT-ST",<br />

CultureAndRegionModifiers.None);<br />

var cultureParent = new CultureInfo("de-AT");<br />

styria.LoadDataFromCultureInfo(cultureParent);<br />

styria.LoadDataFromRegionInfo(new RegionInfo("AT"));<br />

styria.Parent = cultureParent;<br />

styria.RegionNativeName = "Steiermark";<br />

styria.RegionEnglishName = "Styria";<br />

styria.CultureEnglishName = "Styria (Austria)";<br />

styria.CultureNativeName = "Steirisch";<br />

styria.Register();<br />

}<br />

catch (UnauthorizedAccessException ex)<br />

{<br />

Console.WriteLine(ex.Message);<br />

}<br />

}<br />

}<br />

}<br />

code snippet CustomCultures/Program.cs<br />

www.it-ebooks.info

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!