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

适用于