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 。