SerializerProvider.CreateSerializerWriter 方法
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
为将使用指定说明符的指定的 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。
返回
一个派生自 SerializerWriter 的类的对象。
例外
其中一个参数为 Null。
示例
以下示例演示如何返回 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。