共用方式為


ResourceWriter.Generate 方法

定義

以系統預設格式儲存所有資源至輸出資料流。

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

備註

如果方法未由Close應用程式程式代碼呼叫,則Generate方法會隱含地呼叫。

Generate只有在對 和 AddResourceData 的所有呼叫AddResource都已進行之後,才能呼叫一次。 如果寫入資源時發生例外狀況,輸出數據流將會關閉,以防止寫入無效的資訊。

Generate 在一般情況下,不會關閉輸出數據流。 除非您將額外的數據與 .resources 檔案結合,或之後需要存取數據流,否則您應該在 Close 呼叫 Generate之後呼叫 ,或直接呼叫 Close

適用於