ResourceWriter.Generate Metoda

Definicja

Zapisuje wszystkie zasoby do strumienia wyjściowego w domyślnym formacie systemu.

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 ()

Implementuje

Wyjątki

Wystąpił błąd we/wy.

Wystąpił błąd podczas serializacji obiektu.

Ta ResourceWriter funkcja została zamknięta i jej tabela skrótów jest niedostępna.

Przykłady

W poniższym przykładzie kodu użyto Generate metody do zapisania wszystkich obiektów zasobów w ResourceWriter klasie do strumienia wyjściowego

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

Uwagi

Metoda Generate jest wywoływana niejawnie przez metodę Close , jeśli nie jest wywoływana przez kod aplikacji.

Generate może być wywoływany tylko raz, po wszystkich wywołaniach AddResource do i AddResourceData zostały wykonane. Jeśli podczas zapisywania zasobów wystąpi wyjątek, strumień wyjściowy zostanie zamknięty, aby zapobiec zapisywaniu nieprawidłowych informacji.

Generate nie zamyka strumienia wyjściowego w normalnych przypadkach. Jeśli nie łączysz dodatkowych danych z plikiem resources lub potrzebujesz dostępu do strumienia później, wywołaj metodę po wywołaniu Generatemetody lub po prostu wywołaj Close metodę Close.

Dotyczy