Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

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.5.1, 4.5, 4, 3.5, 3.0, 2.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows Phone 8.1, Windows Phone 8, Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.