Beispiel #1
0
        private void btnSerializeArray_Click(object sender, EventArgs e)
        {
            Person pers = new Person(txtFirstName.Text, txtLastName.Text);

            string strMessage = string.Format("File {0} not found.  Deserialization did not succeed!", fileName);

            //Break down pers into bytes - Serialize
            byteArray = BinaryArraySerializer.Serialize(pers);

            if (byteArray != null)
            {
                strMessage = String.Format("{0}, serialized to a series of bytes.   Size = {1}.{2}{3}",
                                           pers.ToString(), byteArray.Length, Environment.NewLine,
                                           "You can now exit application, restart and directly deseialize array!");
            }

            lblMessage.Text = strMessage;
            timer1.Enabled  = true;
        }
Beispiel #2
0
        private void btnDeserializeArray_Click(object sender, EventArgs e)
        {
            //Put together the byteArray to a person object

            string strMessage = string.Format("No byte array in memory. Deserialization cannot continue!");

            if (byteArray != null)
            {
                Person pers = BinaryArraySerializer.Deserialize <Person>(byteArray);

                if (pers != null)
                {
                    strMessage = string.Format("{0},{2} From an array of 0:s and 1:s back as a Person.{2}Size of array = {1}.{2}{2} Teleportation works now!",
                                               pers.ToString(), byteArray.Length, Environment.NewLine);

                    txtFirstName.Text = pers.FirstName.ToUpper();
                    txtLastName.Text  = pers.LastName.ToUpper();
                }
            }

            lblMessage.Text = strMessage;
            timer1.Enabled  = true;
        }