Пример #1
0
        private void exportAsJSONToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (_selectedHero == null)
            {
                return;
            }
            var result       = MessageBox.Show("Do you want to include the image (as a base64 string) in the export?", "Export details", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
            var includeImage = result == DialogResult.Yes;
            var itemToExport = new SerializableSuperHero(_selectedHero, includeImage);

            var serializer = new JsonSerializer();

            serializer.NullValueHandling = NullValueHandling.Ignore;
            var json = "";

            using (var sww = new StringWriter())
                using (JsonWriter writer = new JsonTextWriter(sww))
                {
                    serializer.Serialize(writer, itemToExport);
                    json = sww.ToString();
                    var exportView = new ExportView();
                    exportView.SetData(json);
                    exportView.ShowDialog();
                }
        }
Пример #2
0
        private void exportAsXMLToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (_selectedHero == null)
            {
                return;
            }
            var result       = MessageBox.Show("Do you want to include the image (as a base64 string) in the export?", "Export details", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
            var includeImage = result == DialogResult.Yes;
            var itemToExport = new SerializableSuperHero(_selectedHero, includeImage);

            XmlSerializer serializer = new XmlSerializer(typeof(SerializableSuperHero));
            var           xml        = "";

            using (var sww = new StringWriter())
            {
                using (XmlWriter writer = XmlWriter.Create(sww))
                {
                    serializer.Serialize(writer, itemToExport);
                    xml = sww.ToString();
                    var exportView = new ExportView();
                    exportView.SetData(xml);
                    exportView.ShowDialog();
                }
            }
        }