Udostępnij za pośrednictwem


CultureAndRegionInfoBuilder.Register Metoda

Definicja

Utrwala bieżący CultureAndRegionInfoBuilder obiekt jako kulturę niestandardową na komputerze lokalnym i udostępnia ten obiekt aplikacjom. Wymaga uprawnień administracyjnych.

public:
 void Register();
public void Register ();
member this.Register : unit -> unit
Public Sub Register ()

Wyjątki

Kultura niestandardowa jest już zarejestrowana.

-lub-

Bieżący CultureAndRegionInfoBuilder obiekt ma właściwość, którą należy ustawić przed zarejestrowaniem kultury. Wszystkie kultury, neutralne lub specyficzne, muszą mieć TextInfo i CompareInfo ustawić. Określone kultury muszą mieć również NumberFormatwartości , GregorianDateTimeFormati AvailableCalendars .

Ta metoda zgłasza również, InvalidOperationException jeśli nie zdefiniowano następujących właściwości:

CultureEnglishNameCultureNativeNameCurrencyEnglishNameCurrencyNativeNameISOCurrencySymbolParentRegionEnglishNameRegionNativeNameThreeLetterISOLanguageNameThreeLetterISORegionNameThreeLetterWindowsLanguageNameThreeLetterWindowsRegionNameTwoLetterISOLanguageNameTwoLetterISORegionName

CultureAndRegionInfoBuilder Wartość właściwości obiektu przekracza maksymalną długość lub wartość.

Użytkownik nie ma uprawnień administracyjnych.

Przykłady

W poniższym przykładzie pokazano metodę Register .

// This example demonstrates the System.Globalization.Culture-
// AndRegionInfoBuilder Register method.
// Compile this code example with a reference to sysglobl.dll.

using System;
using System.Globalization;

class Sample
{
    public static void Main()
    {
    CultureAndRegionInfoBuilder cib = null;
    try
    {
// Create a CultureAndRegionInfoBuilder object named "x-en-US-sample".
    Console.WriteLine("Create and explore the CultureAndRegionInfoBuilder...\n");
    cib = new CultureAndRegionInfoBuilder(
                         "x-en-US-sample", CultureAndRegionModifiers.None);

// Populate the new CultureAndRegionInfoBuilder object with culture information.
    CultureInfo ci = new CultureInfo("en-US");
    cib.LoadDataFromCultureInfo(ci);

// Populate the new CultureAndRegionInfoBuilder object with region information.
    RegionInfo  ri = new RegionInfo("US");
    cib.LoadDataFromRegionInfo(ri);

// Display some of the properties of the CultureAndRegionInfoBuilder object.
    Console.WriteLine("CultureName:. . . . . . . . . . {0}", cib.CultureName);
    Console.WriteLine("CultureEnglishName: . . . . . . {0}", cib.CultureEnglishName);
    Console.WriteLine("CultureNativeName:. . . . . . . {0}", cib.CultureNativeName);
    Console.WriteLine("GeoId:. . . . . . . . . . . . . {0}", cib.GeoId);
    Console.WriteLine("IsMetric: . . . . . . . . . . . {0}", cib.IsMetric);
    Console.WriteLine("ISOCurrencySymbol:. . . . . . . {0}", cib.ISOCurrencySymbol);
    Console.WriteLine("RegionEnglishName:. . . . . . . {0}", cib.RegionEnglishName);
    Console.WriteLine("RegionName: . . . . . . . . . . {0}", cib.RegionName);
    Console.WriteLine("RegionNativeName: . . . . . . . {0}", cib.RegionNativeName);
    Console.WriteLine("ThreeLetterISOLanguageName: . . {0}", cib.ThreeLetterISOLanguageName);
    Console.WriteLine("ThreeLetterISORegionName: . . . {0}", cib.ThreeLetterISORegionName);
    Console.WriteLine("ThreeLetterWindowsLanguageName: {0}", cib.ThreeLetterWindowsLanguageName);
    Console.WriteLine("ThreeLetterWindowsRegionName: . {0}", cib.ThreeLetterWindowsRegionName);
    Console.WriteLine("TwoLetterISOLanguageName: . . . {0}", cib.TwoLetterISOLanguageName);
    Console.WriteLine("TwoLetterISORegionName: . . . . {0}", cib.TwoLetterISORegionName);
    Console.WriteLine();

// Register the custom culture.
    Console.WriteLine("Register the custom culture...");
    cib.Register();

// Display some of the properties of the custom culture.
    Console.WriteLine("Create and explore the custom culture...\n");
    ci = new CultureInfo("x-en-US-sample");

    Console.WriteLine("Name: . . . . . . . . . . . . . {0}", ci.Name);
    Console.WriteLine("EnglishName:. . . . . . . . . . {0}", ci.EnglishName);
    Console.WriteLine("NativeName: . . . . . . . . . . {0}", ci.NativeName);
    Console.WriteLine("TwoLetterISOLanguageName: . . . {0}", ci.TwoLetterISOLanguageName);
    Console.WriteLine("ThreeLetterISOLanguageName: . . {0}", ci.ThreeLetterISOLanguageName);
    Console.WriteLine("ThreeLetterWindowsLanguageName: {0}", ci.ThreeLetterWindowsLanguageName);

    Console.WriteLine("\nNote:\n" +
        "Use the example in the Unregister method topic to remove the custom culture.");
    }
    catch (Exception e)
    {
        Console.WriteLine(e);
    }
    }
}
/*
This code example produces the following results:

Create and explore the CultureAndRegionInfoBuilder...

CultureName:. . . . . . . . . . x-en-US-sample
CultureEnglishName: . . . . . . English (United States)
CultureNativeName:. . . . . . . English (United States)
GeoId:. . . . . . . . . . . . . 244
IsMetric: . . . . . . . . . . . False
ISOCurrencySymbol:. . . . . . . USD
RegionEnglishName:. . . . . . . United States
RegionName: . . . . . . . . . . x-en-US-sample
RegionNativeName: . . . . . . . United States
ThreeLetterISOLanguageName: . . eng
ThreeLetterISORegionName: . . . USA
ThreeLetterWindowsLanguageName: ENU
ThreeLetterWindowsRegionName: . USA
TwoLetterISOLanguageName: . . . en
TwoLetterISORegionName: . . . . US

Register the custom culture...
Create and explore the custom culture...

Name: . . . . . . . . . . . . . x-en-US-sample
EnglishName:. . . . . . . . . . English (United States)
NativeName: . . . . . . . . . . English (United States)
TwoLetterISOLanguageName: . . . en
ThreeLetterISOLanguageName: . . eng
ThreeLetterWindowsLanguageName: ENU

Note:
Use the example in the Unregister method topic to remove the custom culture.

*/
' This example demonstrates the System.Globalization.Culture-
' AndRegionInfoBuilder Register method.
' Compile this code example with a reference to sysglobl.dll.

Imports System.Globalization

Class Sample
    Public Shared Sub Main() 
        Dim cib As CultureAndRegionInfoBuilder = Nothing
        Try
            ' Create a CultureAndRegionInfoBuilder object named "x-en-US-sample".
            Console.WriteLine("Create and explore the CultureAndRegionInfoBuilder..." & vbCrLf)
            cib = New CultureAndRegionInfoBuilder("x-en-US-sample", CultureAndRegionModifiers.None)
            
            ' Populate the new CultureAndRegionInfoBuilder object with culture information.
            Dim ci As New CultureInfo("en-US")
            cib.LoadDataFromCultureInfo(ci)
            
            ' Populate the new CultureAndRegionInfoBuilder object with region information.
            Dim ri As New RegionInfo("US")
            cib.LoadDataFromRegionInfo(ri)
            
            ' Display some of the properties of the CultureAndRegionInfoBuilder object.
            Console.WriteLine("CultureName:. . . . . . . . . . {0}", cib.CultureName)
            Console.WriteLine("CultureEnglishName: . . . . . . {0}", cib.CultureEnglishName)
            Console.WriteLine("CultureNativeName:. . . . . . . {0}", cib.CultureNativeName)
            Console.WriteLine("GeoId:. . . . . . . . . . . . . {0}", cib.GeoId)
            Console.WriteLine("IsMetric: . . . . . . . . . . . {0}", cib.IsMetric)
            Console.WriteLine("ISOCurrencySymbol:. . . . . . . {0}", cib.ISOCurrencySymbol)
            Console.WriteLine("RegionEnglishName:. . . . . . . {0}", cib.RegionEnglishName)
            Console.WriteLine("RegionName: . . . . . . . . . . {0}", cib.RegionName)
            Console.WriteLine("RegionNativeName: . . . . . . . {0}", cib.RegionNativeName)
            Console.WriteLine("ThreeLetterISOLanguageName: . . {0}", cib.ThreeLetterISOLanguageName)
            Console.WriteLine("ThreeLetterISORegionName: . . . {0}", cib.ThreeLetterISORegionName)
            Console.WriteLine("ThreeLetterWindowsLanguageName: {0}", cib.ThreeLetterWindowsLanguageName)
            Console.WriteLine("ThreeLetterWindowsRegionName: . {0}", cib.ThreeLetterWindowsRegionName)
            Console.WriteLine("TwoLetterISOLanguageName: . . . {0}", cib.TwoLetterISOLanguageName)
            Console.WriteLine("TwoLetterISORegionName: . . . . {0}", cib.TwoLetterISORegionName)
            Console.WriteLine()
            
            ' Register the custom culture.
            Console.WriteLine("Register the custom culture...")
            cib.Register()
            
            ' Display some of the properties of the custom culture.
            Console.WriteLine("Create and explore the custom culture..." & vbCrLf)
            ci = New CultureInfo("x-en-US-sample")
            
            Console.WriteLine("Name: . . . . . . . . . . . . . {0}", ci.Name)
            Console.WriteLine("EnglishName:. . . . . . . . . . {0}", ci.EnglishName)
            Console.WriteLine("NativeName: . . . . . . . . . . {0}", ci.NativeName)
            Console.WriteLine("TwoLetterISOLanguageName: . . . {0}", ci.TwoLetterISOLanguageName)
            Console.WriteLine("ThreeLetterISOLanguageName: . . {0}", ci.ThreeLetterISOLanguageName)
            Console.WriteLine("ThreeLetterWindowsLanguageName: {0}", ci.ThreeLetterWindowsLanguageName)
            
            Console.WriteLine(vbCrLf & "Note:" & vbCrLf & "Use the example in the " & _
                              "Unregister method topic to remove the custom culture.")
        Catch e As Exception
            Console.WriteLine(e)
        End Try
    
    End Sub
End Class

'This code example produces the following results:
'
'Create and explore the CultureAndRegionInfoBuilder...
'
'CultureName:. . . . . . . . . . x-en-US-sample
'CultureEnglishName: . . . . . . English (United States)
'CultureNativeName:. . . . . . . English (United States)
'GeoId:. . . . . . . . . . . . . 244
'IsMetric: . . . . . . . . . . . False
'ISOCurrencySymbol:. . . . . . . USD
'RegionEnglishName:. . . . . . . United States
'RegionName: . . . . . . . . . . x-en-US-sample
'RegionNativeName: . . . . . . . United States
'ThreeLetterISOLanguageName: . . eng
'ThreeLetterISORegionName: . . . USA
'ThreeLetterWindowsLanguageName: ENU
'ThreeLetterWindowsRegionName: . USA
'TwoLetterISOLanguageName: . . . en
'TwoLetterISORegionName: . . . . US
'
'Register the custom culture...
'Create and explore the custom culture...
'
'Name: . . . . . . . . . . . . . x-en-US-sample
'EnglishName:. . . . . . . . . . English (United States)
'NativeName: . . . . . . . . . . English (United States)
'TwoLetterISOLanguageName: . . . en
'ThreeLetterISOLanguageName: . . eng
'ThreeLetterWindowsLanguageName: ENU
'
'Note:
'Use the example in the Unregister method topic to remove the custom culture.
'

Uwagi

Metoda Register przechowuje kulturę niestandardową jako plik na komputerze lokalnym w podkatalogu Globalizacja katalogu zwróconego przez funkcję Win32 GetWindowsDirectory . Ten proces jest nazywany rejestrowaniem kultury niestandardowej. Po zarejestrowaniu kultury niestandardowej można utworzyć nową kulturę niestandardową, określając nazwę kultury w konstruktorze CultureInfo lub podczas wywoływania CultureInfo.CreateSpecificCulture metody.

Kulturę niestandardową można usunąć, wywołując metodę Unregister .

Dotyczy

Zobacz też