private void OnLoadStateButtonClick(NEventArgs arg1)
        {
            if (m_MemoryStream == null)
            {
                return;
            }

            m_MemoryStream.Seek(0, SeekOrigin.Begin);

            try
            {
                NDomNodeDeserializer deserializer = new NDomNodeDeserializer();

                NTestNode root = (NTestNode)deserializer.LoadFromStream(m_MemoryStream, ENPersistencyFormat.Binary)[0];

/*				NDocumentBlock root = (NDocumentBlock)deserializer.LoadFromStream(m_MemoryStream, ENPersistencyFormat.Binary)[0];
 *
 *                              if (root != null)
 *                              {
 *                                      m_RichText.Document = new NRichTextDocument(root);
 *                              }*/
            }
            catch (Exception ex)
            {
                NTrace.WriteLine(ex.Message);
            }
        }
        private void OnTestSerializationButtonClick(NEventArgs arg)
        {
            ENPersistencyFormat persistencyFormat = (ENPersistencyFormat)arg.TargetNode.Tag;
            NStopwatch          stopwatch;

            try
            {
                Type   nodeType = typeof(NNode);
                Type[] types = nodeType.Assembly.GetTypes();
                int    nodeCount = 0, successfullySerialized = 0;

                stopwatch = NStopwatch.StartNew();
                StringBuilder output = new StringBuilder();
                for (int i = 0, count = types.Length; i < count; i++)
                {
                    Type type = types[i];

                    // not a NNode type, abstract or generic => skip
                    if (!nodeType.IsAssignableFrom(type) || type.IsAbstract || type.IsGenericType)
                    {
                        continue;
                    }

                    NNode node;
                    try
                    {
                        nodeCount++;
                        NNode typeInstance = (NNode)Activator.CreateInstance(type);

                        // Serialize
                        MemoryStream       memoryStream = new MemoryStream();
                        NDomNodeSerializer serializer   = new NDomNodeSerializer();
                        serializer.SerializeDefaultValues = true;
                        serializer.SaveToStream(new NNode[] { typeInstance }, memoryStream, persistencyFormat);

                        // Deserialize to check if the serialization has succeeded
                        NDomNodeDeserializer deserializer = new NDomNodeDeserializer();
                        memoryStream = new MemoryStream(memoryStream.ToArray());
                        node         = deserializer.LoadFromStream(memoryStream, persistencyFormat)[0];

                        output.AppendLine("Sucessfully serialized node type [" + type.Name + "].");
                        successfullySerialized++;
                    }
                    catch (Exception ex)
                    {
                        output.AppendLine("Failed to serialize node type [" + type.Name + "]. Exception was [" + ex.Message + "]");
                    }
                }

                stopwatch.Stop();

                output.AppendLine("==================================================");
                output.AppendLine("Nodes serialized: " + successfullySerialized.ToString() + " of " + nodeCount.ToString());
                output.AppendLine("Time elapsed: " + stopwatch.ElapsedMilliseconds.ToString() + " ms");

                m_TextBox.Text = output.ToString();
                m_TextBox.SetCaretPos(new NTextPosition(m_TextBox.Text.Length, false));
                m_TextBox.EnsureCaretVisible();
            }
            catch (Exception ex)
            {
                NTrace.WriteLine(ex.Message);
            }

            // Restore the default cursor
            this.OwnerWindow.Cursor = null;
        }