IBinarySerialize.Read(BinaryReader) 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
從其二進位形式產生使用者定義型別 (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)
參數
從中還原序列化物件的 BinaryReader 資料流。
範例
下列範例顯示 UDT 方法的實 Read 作,其會使用 BinaryReader 將先前保存的 UDT 取消串行化。 這個範例假設 UDT 有兩個資料屬性: StringValue
和 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;
}
備註
方法 Read 必須使用 方法所 Write 撰寫的資訊來重新建構物件。