Rediger

Del via


SerializerWriter Constructor

Definition

Initializes a new instance of the SerializerWriter class.

protected:
 SerializerWriter();
protected SerializerWriter ();
Protected Sub New ()

Examples

The following example shows how to create a SerializerWriter using the SerializerProvider.CreateSerializerWriter method.

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

Instances of SerializerWriter should be created by using the CreateSerializerWriter method of a SerializerProvider object, not the CreateSerializerWriter method of an ISerializerFactory object.

Applies to