IBinarySerialize.Read(BinaryReader) メソッド

定義

ユーザー定義型 (UDT) またはユーザー定義集計をバイナリ形式から生成します。

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)

パラメーター

r
BinaryReader

オブジェクトの逆シリアル化元である BinaryReader ストリーム。

次の例は、 を使用BinaryReaderしてRead以前に永続化された UDT をシリアル化解除する UDT の メソッドの実装を示しています。 この例では、UDT に と の 2 つのデータ プロパティ StringValueDoubleValueがあることを前提としています。

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

注釈

メソッドは Read 、 メソッドによって書き込まれた情報を使用してオブジェクトを再構成する Write 必要があります。

適用対象