CultureAndRegionInfoBuilder.Save(String) 方法
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
将当前 CultureAndRegionInfoBuilder 对象的 XML 表示形式写入指定的文件。
public:
void Save(System::String ^ filename);
public void Save (string filename);
member this.Save : string -> unit
Public Sub Save (filename As String)
参数
- filename
- String
包含此自定义区域性的 XML 表示形式的文件的名称。
例外
filename
为 null
。
filename
为空字符串 ("")。
当前 DateTimeFormatInfo 对象中包含的 TextInfo、NumberFormatInfo 或 CultureAndRegionInfoBuilder 对象的某个属性值无效。
示例
以下示例演示 和 SaveCreateFromLdml 方法。
// This example demonstrates the CultureAndRegionInfoBuilder.Save and
// CreateFromLdml methods.
// Compile this example with a reference to sysglobl.dll.
using System;
using System.Globalization;
using System.IO;
using System.Xml;
class Sample
{
public static void Main()
{
string savedCARIB = "mySavedCARIB.xml";
string msg1 = "The name of the original CultureAndRegionInfoBuilder" +
" is \"{0}\".";
string msg2 = "Reconstituting the CultureAndRegionInfoBuilder object " +
"from \"{0}\".";
string msg3 = "The name of the reconstituted CultureAndRegionInfoBuilder" +
" is \"{0}\".";
// Construct a new, privately used culture that extends the en-US culture
// provided by the .NET Framework. In this sample, the CultureAndRegion-
// Types.Specific parameter creates a minimal CultureAndRegionInfoBuilder
// object that you must populate with culture and region information.
CultureAndRegionInfoBuilder cib1 = null;
CultureAndRegionInfoBuilder cib2 = null;
try {
cib1 = new CultureAndRegionInfoBuilder(
"x-en-US-sample", CultureAndRegionModifiers.None);
}
catch (ArgumentException ae)
{
Console.WriteLine(ae);
return;
}
// Populate the new CultureAndRegionInfoBuilder object with culture information.
CultureInfo ci = new CultureInfo("en-US");
cib1.LoadDataFromCultureInfo(ci);
// Populate the new CultureAndRegionInfoBuilder object with region information.
RegionInfo ri = new RegionInfo("US");
cib1.LoadDataFromRegionInfo(ri);
// Display a property of the new custom culture.
Console.Clear();
Console.WriteLine(msg1, cib1.CultureName);
// Save the new CultureAndRegionInfoBuilder object in the specified file in
// LDML format. The file is saved in the same directory as the application
// that calls the Save method.
Console.WriteLine("Saving the custom culture to a file...");
try {
cib1.Save( savedCARIB );
}
catch (IOException exc)
{
Console.WriteLine("** I/O exception: {0}", exc.Message);
return;
}
// Create a new CultureAndRegionInfoBuilder object from the persisted file.
Console.WriteLine(msg2, savedCARIB);
try {
cib2 = CultureAndRegionInfoBuilder.CreateFromLdml( savedCARIB );
}
catch (XmlException xe)
{
Console.WriteLine("** XML validation exception: {0}", xe.Message);
return;
}
// Display a property of the resonstituted custom culture.
Console.WriteLine(msg3, cib2.CultureName);
// At this point you could call the Register method and make the reconstituted
// custom culture available to other applications. The mySavedCARIB.xml file
// remains on your computer.
}
}
/*
This code example produces the following results:
The name of the original CultureAndRegionInfoBuilder is "x-en-US-sample".
Saving the custom culture to a file...
Reconstituting the CultureAndRegionInfoBuilder object from "mySavedCARIB.xml".
The name of the reconstituted CultureAndRegionInfoBuilder is "x-en-US-sample".
*/
' This example demonstrates the CultureAndRegionInfoBuilder.Save and
' CreateFromLdml methods.
' Compile this example with a reference to sysglobl.dll.
Imports System.Globalization
Imports System.IO
Imports System.Xml
Class Sample
Public Shared Sub Main()
Dim savedCARIB As String = "mySavedCARIB.xml"
Dim msg1 As String = "The name of the original CultureAndRegionInfoBuilder" & _
" is ""{0}""."
Dim msg2 As String = "Reconstituting the CultureAndRegionInfoBuilder object " & _
"from ""{0}""."
Dim msg3 As String = "The name of the reconstituted CultureAndRegionInfoBuilder" & _
" is ""{0}""."
' Construct a new, privately used culture that extends the en-US culture
' provided by the .NET Framework. In this sample, the CultureAndRegion-
' Types.Specific parameter creates a minimal CultureAndRegionInfoBuilder
' object that you must populate with culture and region information.
Dim cib1 As CultureAndRegionInfoBuilder = Nothing
Dim cib2 As CultureAndRegionInfoBuilder = Nothing
Try
cib1 = New CultureAndRegionInfoBuilder("x-en-US-sample", _
CultureAndRegionModifiers.None)
Catch ae As ArgumentException
Console.WriteLine(ae)
Return
End Try
' Populate the new CultureAndRegionInfoBuilder object with culture information.
Dim ci As New CultureInfo("en-US")
cib1.LoadDataFromCultureInfo(ci)
' Populate the new CultureAndRegionInfoBuilder object with region information.
Dim ri As New RegionInfo("US")
cib1.LoadDataFromRegionInfo(ri)
' Display a property of the new custom culture.
Console.Clear()
Console.WriteLine(msg1, cib1.CultureName)
' Save the new CultureAndRegionInfoBuilder object in the specified file in
' LDML format. The file is saved in the same directory as the application
' that calls the Save method.
Console.WriteLine("Saving the custom culture to a file...")
Try
cib1.Save(savedCARIB)
Catch exc As IOException
Console.WriteLine("** I/O exception: {0}", exc.Message)
Return
End Try
' Create a new CultureAndRegionInfoBuilder object from the persisted file.
Console.WriteLine(msg2, savedCARIB)
Try
cib2 = CultureAndRegionInfoBuilder.CreateFromLdml(savedCARIB)
Catch xe As XmlException
Console.WriteLine("** XML validation exception: {0}", xe.Message)
Return
End Try
' Display a property of the resonstituted custom culture.
Console.WriteLine(msg3, cib2.CultureName)
' At this point you could call the Register method and make the reconstituted
' custom culture available to other applications. The mySavedCARIB.xml file
' remains on your computer.
End Sub
End Class
'This code example produces the following results:
'
'The name of the original CultureAndRegionInfoBuilder is "x-en-US-sample".
'Saving the custom culture to a file...
'Reconstituting the CultureAndRegionInfoBuilder object from "mySavedCARIB.xml".
'The name of the reconstituted CultureAndRegionInfoBuilder is "x-en-US-sample".
'
注解
方法 Save 以名为 Locale Data Markup Language (LDML) 版本 1.1 的 XML 格式将当前 CultureAndRegionInfoBuilder 对象写入参数指定的 filename
文件。 方法 CreateFromLdml 执行 方法的 Save 反向操作。
有关 LDML 文件格式的信息,请参阅 CreateFromLdml 方法。 有关 LDML 标准的信息,请参阅 Unicode Consortium 网站上的 Unicode 技术标准 #35“Locale Data Markup Language (LDML) ”。