IBinarySerialize.Read(BinaryReader) Metodo

Definizione

Genera un tipo definito dall'utente (UDT) o un aggregato definito dall'utente dalla relativa forma binaria.

public:
 void Read(System::IO::BinaryReader ^ r);
public void Read (System.IO.BinaryReader r);
abstract member Read : System.IO.BinaryReader -> unit
Public Sub Read (r As BinaryReader)

Parametri

r
BinaryReader

Flusso BinaryReader da cui viene deserializzato l'oggetto.

Esempio

Nell'esempio seguente viene illustrata l'implementazione del Read metodo di un tipo definito dall'utente, che usa un BinaryReader oggetto per de-serializzare un tipo definito dall'utente persistente in precedenza. In questo esempio si presuppone che il tipo definito dall'utente abbia due proprietà di dati: StringValue e DoubleValue.

// 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 Read(System.IO.BinaryReader r)
{

    int maxStringSize = 20;
    char[] chars;
    int stringEnd;
    string stringValue;
    double doubleValue;

    // Read the characters from the binary stream.
    chars = r.ReadChars(maxStringSize);

    // Find the start of the null character padding.
    stringEnd = Array.IndexOf(chars, '\0');

    if (stringEnd == 0)
    {
        stringValue = null;
        return;
    }

    // Build the string from the array of characters.
    stringValue = new String(chars, 0, stringEnd);

    // Read the double value from the binary stream.
    doubleValue = r.ReadDouble();

    // Set the object's properties equal to the values.
    this.StringValue = stringValue;
    this.DoubleValue = doubleValue;
}

Commenti

Il Read metodo deve ricostituire l'oggetto usando le informazioni scritte dal Write metodo .

Si applica a