public unsafe void Test_ReadWrite() { int nodesCount = 1 + 4 + 4 * 4 + 4 * 4 * 4; TestTree tree = new TestTree(nodesCount); int idx = 0; CreateTestTree(tree, ref idx, 0, 3, 4); tree.Version.Major = 4; tree.Version.Minor = 2; tree.UserData = 1234567; MemoryStream ms = new MemoryStream(); BinaryWriter w = new BinaryWriter(ms); tree.Write(w); byte[] buffer = ms.ToArray(); ms = new MemoryStream(buffer); BinaryReader r = new BinaryReader(ms); TestTree tree1 = TestTree.Read <TestTree>(r); Assert.AreEqual(tree.Version, tree1.Version); Assert.AreEqual(tree.UserData, tree1.UserData); Assert.AreEqual(tree.NodesCount, tree1.NodesCount); for (int i = 0; i < tree.NodesCount; ++i) { Assert.AreEqual(tree.GetDepth(i), tree1.GetDepth(i)); Assert.AreEqual(tree.Nodes[i].Id, tree1.Nodes[i].Id); } }