Exemplo n.º 1
0
        private void btn_open_Click(object sender, EventArgs e)
        {
            var dlg = new OpenFileDialog();

            dlg.Filter = "Any file(xml,bin,txt or their encoded versions)|*.*";

            if (dlg.ShowDialog() == DialogResult.Cancel)
            {
                return;
            }
            NewSerializer newSerializer = new NewSerializer();

            Clear();
            List <Fact> newList = null;

            newList = (List <Fact>)newSerializer.GetfileName_Serialization(dlg.FileName).Deserialize(typeof(List <Fact>), dlg.FileName);

            foreach (Fact obj in newList)
            {
                Type newObjectType = obj.GetType();
                try
                {
                    listBoxObj.Items.Add(obj.ToString() + ' ' + newObjectType.GetProperty("LastName").GetValue(obj).ToString());
                }
                catch
                {
                    listBoxObj.Items.Add(obj.ToString() + ' ' + newObjectType.GetProperty("number").GetValue(obj).ToString());
                }
                objects.Add(obj);
            }
        }
Exemplo n.º 2
0
        private void btn_save_Click(object sender, EventArgs e)
        {
            SaveFileDialog dlg = new SaveFileDialog
            {
                FileName = "Fact",
                Filter   = "Encoded Binary data (*.bin)|*.bin|Encoded XML file(*.xml)|*.xml|Encoded Text file(*.txt)|*.txt"
            };

            if (dlg.ShowDialog() == DialogResult.Cancel)
            {
                return;
            }
            NewSerializer newSerializer = new NewSerializer();

            newSerializer.GetfileName_Serialization(dlg.FileName).Serialize(objects, dlg.FileName);
        }