Editar

Partilhar via


SerializerProvider.CreateSerializerWriter Method

Definition

Initializes an object derived from the abstract SerializerWriter class for the specified Stream that will use the specified descriptor.

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

Parameters

serializerDescriptor
SerializerDescriptor

A SerializerDescriptor that contains serialization information for the SerializerWriter.

stream
Stream

The Stream to which the returned object writes.

Returns

An object of a class derived from SerializerWriter.

Exceptions

One of the parameters is null.

The serializerDescriptor is specifying the wrong version.

-or-

It is not registered.

-or-

The assembly file cannot be found.

-or-

The assembly cannot be loaded.

Examples

The following example shows using CreateSerializerWriter to return a plug-in serialization writer for saving a file.

// 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;
}

Remarks

Only fully trusted applications can call CreateSerializerWriter.

Applies to