IBinarySerialize.Read(BinaryReader) Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Generates a user-defined type (UDT) or user-defined aggregate from its binary form.
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)
Parameters
The BinaryReader stream from which the object is deserialized.
Examples
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
// 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;
}
Remarks
The Read method must reconstitute your object using the information written by the Write method.