Partilhar via


Método ISyncFilter.Serialize

Quando substituído por uma classe derivada, serializa o filtro para uma matriz de bytes.

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

Sintaxe

'Declaração
Function Serialize As Byte()
'Uso
Dim instance As ISyncFilter
Dim returnValue As Byte()

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

Valor de retorno

Os dados do filtro serializados para uma matriz de bytes.

Comentários

Se não for necessário serializar o filtro, esse método poderá lançar NotImplementedException.

Exemplo

O exemplo a seguir usa um objeto BinaryWriter para serializar o filtro personalizado para uma matriz de bytes.

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

Consulte também

Referência

Interface ISyncFilter
Membros ISyncFilter
Namespace Microsoft.Synchronization