ResourceWriter.Generate 方法
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
将所有资源以系统默认格式保存到输出流。
public:
virtual void Generate();
public:
void Generate();
public void Generate ();
abstract member Generate : unit -> unit
override this.Generate : unit -> unit
member this.Generate : unit -> unit
Public Sub Generate ()
实现
例外
出现 I/O 错误。
对象序列化期间出现错误。
该 ResourceWriter 已关闭,并且哈希表不可用。
示例
下面的代码示例使用 Generate 方法将类中的所有 ResourceWriter 资源对象写入输出流
using namespace System;
using namespace System::Resources;
using namespace System::IO;
int main()
{
// Create a file stream to encapsulate items.resources.
FileStream^ fs = gcnew FileStream( "items.resources",FileMode::OpenOrCreate,FileAccess::Write );
// Open a resource writer to write from the stream.
IResourceWriter^ writer = gcnew ResourceWriter( fs );
// Add resources to the resource writer.
writer->AddResource( "String 1", "First String" );
writer->AddResource( "String 2", "Second String" );
writer->AddResource( "String 3", "Third String" );
// Generate the resources, and close the writer.
writer->Generate();
writer->Close();
}
using System;
using System.Resources;
using System.IO;
public class WriteResources
{
public static void Main(string[] args)
{
// Create a file stream to encapsulate items.resources.
FileStream fs = new FileStream("items.resources",
FileMode.OpenOrCreate,FileAccess.Write);
// Open a resource writer to write from the stream.
IResourceWriter writer = new ResourceWriter(fs);
// Add resources to the resource writer.
writer.AddResource("String 1", "First String");
writer.AddResource("String 2", "Second String");
writer.AddResource("String 3", "Third String");
// Generate the resources, and close the writer.
writer.Generate();
writer.Close();
}
}
Imports System.Resources
Imports System.IO
Public Class WriteResources
Public Shared Sub Main(ByVal args() As String)
' Create a file stream to encapsulate items.resources.
Dim fs As New FileStream("items.resources", _
FileMode.OpenOrCreate, FileAccess.Write)
' Open a resource writer to write from the stream.
Dim writer = New ResourceWriter(fs)
' Add resources to the resource writer.
writer.AddResource("String 1", "First String")
writer.AddResource("String 2", "Second String")
writer.AddResource("String 3", "Third String")
' Generate the resources, and close the writer.
writer.Generate()
writer.Close()
End Sub
End Class
注解
Generate如果应用程序代码未调用 方法,则该方法将隐式Close调用该方法。
Generate在对 和 AddResourceData 的所有调用后,只能调用AddResource一次。 如果在写入资源时发生异常,输出流将关闭以防止写入无效信息。
Generate 在正常情况下不会关闭输出流。 除非将额外数据与 .resources 文件组合在一起,或者之后需要访问流,否则应在调用 后调用 CloseGenerate,或者只需调用 即可。Close