Visual Basic (Declaration) | |
---|---|
Public Shared ReadOnly Guid As ISerializer(Of Guid) |
C# | |
---|---|
public static readonly ISerializer<Guid> Guid |
Library/Library.Test/TestPrimitiveSerializer.cs
C# | Copy Code |
---|---|
ISerializer<KeyValuePair<int, Guid>> ser = new KeyValueSerializer<int, Guid>(PrimitiveSerializer.Int32, PrimitiveSerializer.Guid); Dictionary<int, Guid> values = new Dictionary<int, Guid> { { -1, Guid.NewGuid() }, { 0, Guid.NewGuid() }, { 1, Guid.NewGuid() }, { int.MaxValue, Guid.NewGuid() }, }; foreach (KeyValuePair<int, Guid> value in values) { using (MemoryStream ms = new MemoryStream()) { ser.WriteTo(value, ms); // add random bytes, every value should know it's length and not rely on EOF. byte[] bytes = new byte[256 - ms.Position]; _random.NextBytes(bytes); ms.Write(bytes, 0, bytes.Length); // seek begin and read. ms.Position = 0; Assert.AreEqual(value, ser.ReadFrom(ms)); } } |
VB.NET | Copy Code |
---|---|
Dim ser As ISerializer(Of KeyValuePair(Of Integer, Guid)) = New KeyValueSerializer(Of Integer, Guid)(PrimitiveSerializer.Int32, PrimitiveSerializer.Guid) Dim values As New Dictionary(Of Integer, Guid)() From { _ {-1, Guid.NewGuid()}, _ {0, Guid.NewGuid()}, _ {1, Guid.NewGuid()}, _ {Integer.MaxValue, Guid.NewGuid()} _ } For Each value As KeyValuePair(Of Integer, Guid) In values Using ms As New MemoryStream() ser.WriteTo(value, ms) ' add random bytes, every value should know it's length and not rely on EOF. Dim bytes As Byte() = New Byte(256 - ms.Position) {} _random.NextBytes(bytes) ms.Write(bytes, 0, bytes.Length) ' seek begin and read. ms.Position = 0 Assert.AreEqual(value, ser.ReadFrom(ms)) End Using Next |
Target Platforms: Windows XP, Windows Server 2003, Windows Vista, Windows Server 2008, Windows 7
Reference
PrimitiveSerializer ClassPrimitiveSerializer Members
Used By
TestTransactionLog.TestBenchmarkWriteSpeed()ThreadedMassInsertTest.TestConcurrency()