共用方式為


SerializerProvider.CreateSerializerWriter 方法

定義

初始化從指定之 SerializerWriter (將使用指定的描述項) 的抽象 Stream 類別衍生的物件。

public:
 System::Windows::Documents::Serialization::SerializerWriter ^ CreateSerializerWriter(System::Windows::Documents::Serialization::SerializerDescriptor ^ serializerDescriptor, System::IO::Stream ^ stream);
public System.Windows.Documents.Serialization.SerializerWriter CreateSerializerWriter (System.Windows.Documents.Serialization.SerializerDescriptor serializerDescriptor, System.IO.Stream stream);
member this.CreateSerializerWriter : System.Windows.Documents.Serialization.SerializerDescriptor * System.IO.Stream -> System.Windows.Documents.Serialization.SerializerWriter
Public Function CreateSerializerWriter (serializerDescriptor As SerializerDescriptor, stream As Stream) As SerializerWriter

參數

serializerDescriptor
SerializerDescriptor

SerializerDescriptor,包含 SerializerWriter 的序列化資訊。

stream
Stream

傳回的物件要寫入至其中的 Stream

傳回

SerializerWriter

衍生自 SerializerWriter 之類別的物件。

例外狀況

其中一個參數為 null。

serializerDescriptor 指定的版本錯誤。

-或- 其未註冊。

-或- 找不到指定的組件檔案。

-或- 無法載入組件。

範例

下列範例示範如何使用 CreateSerializerWriter 傳回外掛程式序列化寫入器來儲存檔案。

// Create a SerializerProvider for accessing plug-in serializers.
SerializerProvider serializerProvider = new SerializerProvider();

// Locate the serializer that matches the fileName extension.
SerializerDescriptor selectedPlugIn = null;
foreach ( SerializerDescriptor serializerDescriptor in
                serializerProvider.InstalledSerializers )
{
    if ( serializerDescriptor.IsLoadable &&
         fileName.EndsWith(serializerDescriptor.DefaultFileExtension) )
    {   // The plug-in serializer and fileName extensions match.
        selectedPlugIn = serializerDescriptor;
        break; // foreach
    }
}

// If a match for a plug-in serializer was found,
// use it to output and store the document.
if (selectedPlugIn != null)
{
    Stream package = File.Create(fileName);
    SerializerWriter serializerWriter =
        serializerProvider.CreateSerializerWriter(selectedPlugIn,
                                                  package);
    IDocumentPaginatorSource idoc =
        flowDocument as IDocumentPaginatorSource;
    serializerWriter.Write(idoc.DocumentPaginator, null);
    package.Close();
    return true;
}

備註

只有完全信任的應用程式可以呼叫 CreateSerializerWriter

適用於