Udostępnij za pośrednictwem


ISyncFilter.Serialize Method

When overridden by a derived class, serializes the filter to an array of bytes.

Namespace: Microsoft.Synchronization
Assembly: Microsoft.Synchronization (in microsoft.synchronization.dll)

Syntax

'Declaration
Function Serialize As Byte()
'Usage
Dim instance As ISyncFilter
Dim returnValue As Byte()

returnValue = instance.Serialize
byte[] Serialize ()
array<unsigned char>^ Serialize ()
byte[] Serialize ()
function Serialize () : byte[]

Return Value

The filter data serialized to an array of bytes.

Remarks

If it is not necessary to serialize the filter, this method can throw NotImplementedException.

Example

The following example uses a BinaryWriter object to serialize the custom filter to a byte array.

Public Function Serialize() As Byte() Implements ISyncFilter.Serialize
    Dim memStream As New MemoryStream()
    Dim biWriter As New BinaryWriter(memStream, Encoding.Unicode)

    SerializeToBinaryWriter(biWriter)

    Return memStream.GetBuffer()
End Function

Private Sub SerializeToBinaryWriter(ByVal biWriter As BinaryWriter)
    Dim hasFilterForgottenKnowledge As Boolean = (_filterForgottenKnowledge IsNot Nothing)

    biWriter.Write(hasFilterForgottenKnowledge)

    biWriter.Write(_filter)

    If _filterForgottenKnowledge IsNot Nothing Then
        Dim serializedForgottenKnowledge As Byte() = _filterForgottenKnowledge.Serialize()
        biWriter.Write(serializedForgottenKnowledge.Length)
        biWriter.Write(serializedForgottenKnowledge)
    End If
End Sub
public byte[] Serialize()
{
    MemoryStream memStream = new MemoryStream();
    BinaryWriter biWriter = new BinaryWriter(memStream, Encoding.Unicode);

    SerializeToBinaryWriter(biWriter);

    return memStream.GetBuffer();
}

private void SerializeToBinaryWriter(BinaryWriter biWriter)
{
    bool hasFilterForgottenKnowledge = (null != _filterForgottenKnowledge);

    biWriter.Write(hasFilterForgottenKnowledge);

    biWriter.Write(_filter);

    if (null != _filterForgottenKnowledge)
    {
        byte[] serializedForgottenKnowledge = _filterForgottenKnowledge.Serialize();
        biWriter.Write(serializedForgottenKnowledge.Length);
        biWriter.Write(serializedForgottenKnowledge);
    }
}

See Also

Reference

ISyncFilter Interface
ISyncFilter Members
Microsoft.Synchronization Namespace