CultureAndRegionInfoBuilder.Register Método
Definición
Importante
Parte de la información hace referencia a la versión preliminar del producto, que puede haberse modificado sustancialmente antes de lanzar la versión definitiva. Microsoft no otorga ninguna garantía, explícita o implícita, con respecto a la información proporcionada aquí.
Almacena el objeto CultureAndRegionInfoBuilder actual como una referencia cultural personalizada en el equipo local y pone esa referencia cultural a disposición de las aplicaciones. Requiere privilegios de administrador.
public:
void Register();
public void Register ();
member this.Register : unit -> unit
Public Sub Register ()
Excepciones
La referencia cultural personalizada ya está registrada.
o bien
El objeto CultureAndRegionInfoBuilder actual tiene una propiedad que debe estar establecida para poder registrar la referencia cultural. Todas las referencias culturales, neutras o específicas, deben tener establecidas las propiedades TextInfo y CompareInfo. Las referencias culturales específicas también deben tener establecidas NumberFormat, GregorianDateTimeFormat y AvailableCalendars.
Este método también produce la excepción InvalidOperationException si no se han definido las siguientes propiedades:
CultureEnglishNameCultureNativeNameCurrencyEnglishNameCurrencyNativeNameISOCurrencySymbolParentRegionEnglishNameRegionNativeNameThreeLetterISOLanguageNameThreeLetterISORegionNameThreeLetterWindowsLanguageNameThreeLetterWindowsRegionNameTwoLetterISOLanguageNameTwoLetterISORegionName
El valor de una propiedad del objeto CultureAndRegionInfoBuilder rebasa su longitud o valor máximo.
El usuario no tiene privilegios de administrador.
Ejemplos
En el siguiente ejemplo se muestra el Register método.
// 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.
'
Comentarios
El Register método almacena una referencia cultural personalizada como un archivo en el equipo local, en el subdirectorio Globalization del directorio devuelto por la función GetWindowsDirectory de Win32 . Este proceso se denomina registro de la referencia cultural personalizada. Una vez registrada la referencia cultural personalizada, se puede crear una nueva referencia cultural personalizada especificando el nombre de la referencia cultural en un CultureInfo constructor o al llamar al CultureInfo.CreateSpecificCulture método .
La referencia cultural personalizada se puede quitar llamando al Unregister método .