IBinarySerialize.Write(BinaryWriter) Método

Definición

Convierte un tipo definido por el usuario (UDT) o un agregado definido por el usuario en su formato binario, para que se pueda almacenar.

public:
 void Write(System::IO::BinaryWriter ^ w);
public void Write (System.IO.BinaryWriter w);
abstract member Write : System.IO.BinaryWriter -> unit
Public Sub Write (w As BinaryWriter)

Parámetros

w
BinaryWriter

Secuencia de BinaryWriter en la que se serializa el UDT o el agregado definido por el usuario.

Ejemplos

En el ejemplo siguiente se muestra la Write implementación del método de un UDT, que usa para BinaryWriter serializar el UDT en el formato binario definido por el usuario. El propósito del relleno de caracteres null es asegurarse de que el valor de cadena está completamente separado del valor doble, de modo que un UDT se compare con otro en el código Transact-SQL, los bytes de cadena se comparan con los bytes de cadena y los bytes dobles se comparan con los bytes dobles.

// The binary layout is as follows:
//    Bytes 0 - 19: string text, padded to the right with null characters
//    Bytes 20+: Double value

// using Microsoft.SqlServer.Server;
public void Write(System.IO.BinaryWriter w)
{
    int maxStringSize = 20;
    string stringValue = "The value of PI: ";
    string paddedString;
    double value = 3.14159;

    // Pad the string from the right with null characters.
    paddedString = stringValue.PadRight(maxStringSize, '\0');

    // Write the string value one byte at a time.
    for (int i = 0; i < paddedString.Length; i++)
    {
        w.Write(paddedString[i]);
    }

    // Write the double value.
    w.Write(value);
}

Comentarios

Escriba información suficiente en el flujo binario para permitir que el método reconstituya el UDT o el agregado definido por el Read usuario.

Se aplica a