Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Read Method
Collapse the table of content
Expand the table of content

IBinarySerialize.Read Method

Generates a user-defined type (UDT) or user-defined aggregate from its binary form.

Namespace:  Microsoft.SqlServer.Server
Assembly:  System.Data (in System.Data.dll)

void Read(
	BinaryReader r
)

Parameters

r
Type: System.IO.BinaryReader

The BinaryReader stream from which the object is deserialized.

The Read method must reconstitute your object using the information written by the Write method.

The following example shows the implementation of the Read method of a UDT, which uses a BinaryReader to de-serialize a previously persisted UDT. This example assumes that the UDT has two data properties: StringValue and DoubleValue.

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

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

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5, 3.0, 2.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1
Show:
© 2015 Microsoft