CSharpTest.Net
Guid Field
See Also  Example Send Feedback Download Help File
CSharpTest.Net.Library Assembly > CSharpTest.Net.Serialization Namespace > PrimitiveSerializer Class : Guid Field

Glossary Item Box

Gets a typed version of the PrimitiveSerializer

Syntax

Visual Basic (Declaration) 
Public Shared ReadOnly Guid As ISerializer(Of Guid)
C# 
public static readonly ISerializer<Guid> Guid

Example

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.NETCopy 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

Requirements

Target Platforms: Windows XP, Windows Server 2003, Windows Vista, Windows Server 2008, Windows 7

See Also

Reference

PrimitiveSerializer Class
PrimitiveSerializer Members

Used By

TestTransactionLog.TestBenchmarkWriteSpeed()
ThreadedMassInsertTest.TestConcurrency()

Source Code

Library/Serialization/PrimitiveSerializer.cs

Generated with Document! X 2011 by Innovasys