Click here to Skip to main content
15,868,141 members
Home / Discussions / C#
   

C#

 
AnswerRe: CsvHelper, EBay Order Csv file, not sure how to handle header with quotes and first line of commas Pin
jkirkerx3-Sep-20 6:31
professionaljkirkerx3-Sep-20 6:31 
AnswerRe: CsvHelper, EBay Order Csv file, not sure how to handle header with quotes and first line of commas Pin
Gerry Schmitz3-Sep-20 10:23
mveGerry Schmitz3-Sep-20 10:23 
QuestionConnect POST server call with HttpListener C# Pin
jdamiancabello2-Sep-20 0:21
jdamiancabello2-Sep-20 0:21 
AnswerRe: Connect POST server call with HttpListener C# Pin
Afzaal Ahmad Zeeshan3-Sep-20 5:19
professionalAfzaal Ahmad Zeeshan3-Sep-20 5:19 
QuestionInheritance problem Pin
Croccodillo19711-Sep-20 5:22
Croccodillo19711-Sep-20 5:22 
AnswerRe: Inheritance problem Pin
Richard Deeming1-Sep-20 7:26
mveRichard Deeming1-Sep-20 7:26 
GeneralRe: Inheritance problem Pin
Croccodillo19711-Sep-20 21:58
Croccodillo19711-Sep-20 21:58 
AnswerRe: Inheritance problem Pin
BillWoodruff9-Sep-20 21:16
professionalBillWoodruff9-Sep-20 21:16 
See if Richard's excellent response, and this code ... gives you some ideas:
using System;
using System.IO;
using System.Xml.Serialization;

namespace TextToClasses
{
    public class BaseClass
    {
        public class Data
        {
            public int Data1;
            public int Data2;
            public string Data3;

            public Data()
            {
            }

            public Data(int data1, int data2, string data3)
            {
                Data1 = data1;
                Data2 = data2;
                Data3 = data3;
            }
        }

        public Data TheData;

        public bool Save(string Filename, Data data)
        {
            var xs = new XmlSerializer(data.GetType());

            using (TextWriter sw = new StreamWriter(Filename))
            {
                xs.Serialize(sw, data);
            }

            return File.Exists(Filename);
        }

        public Data Load(string Filename, Type type)
        {
            Data rslt;

            var xs = new XmlSerializer(type);

            using (var sr = new StreamReader(Filename))
            {
                rslt = (Data) xs.Deserialize(sr);
            }

            return rslt;
        }
    }

    public class DerivedClass : BaseClass
    {
        public class DerivedData : BaseClass.Data
        {
            public int Data4;

            public DerivedData()
            {
            }

            public DerivedData(int data4, int data1, int data2, string data3) : base(data1, data2, data3)
            {
                Data4 = data4;
            }
        }
    }
}
Sample usage:
BaseClass bc = new BaseClass();
bc.TheData = new BaseClass.Data(1,1,"BaseString");

bc.Save(@"C:\Users\test_user\Desktop\Basedata.xml", bc.TheData);

var bcdata = bc.Load(@"C:\Users\test_user\Desktop\Basedata.xml", bc.TheData.GetType());

DerivedClass dc = new DerivedClass();
dc.TheData = new DerivedClass.DerivedData(4, 2, 2, "DerivedString");

dc.Save(@"C:\Users\test_user\Desktop\Deriveddata.xml", dc.TheData);

var dcdata = dc.Load(@"C:\Users\test_user\Desktop\Deriveddata.xml", dc.TheData.GetType());
I am sure this can be improved Smile | :)
«One day it will have to be officially admitted that what we have christened reality is an even greater illusion than the world of dreams.» Salvador Dali

QuestionHow to reliably exit Outlook using Interop.Outlook? Pin
Server Automator30-Aug-20 14:43
professionalServer Automator30-Aug-20 14:43 
AnswerRe: How to reliably exit Outlook using Interop.Outlook? Pin
Gerry Schmitz31-Aug-20 4:50
mveGerry Schmitz31-Aug-20 4:50 
AnswerRe: How to reliably exit Outlook using Interop.Outlook? Pin
Dave Kreskowiak31-Aug-20 12:12
mveDave Kreskowiak31-Aug-20 12:12 
AnswerRe: How to reliably exit Outlook using Interop.Outlook? Pin
Mycroft Holmes31-Aug-20 12:15
professionalMycroft Holmes31-Aug-20 12:15 
Questionfind TIMES in string of text Pin
free-pizza30-Aug-20 13:52
free-pizza30-Aug-20 13:52 
AnswerRe: find TIMES in string of text Pin
Richard Andrew x6430-Aug-20 15:03
professionalRichard Andrew x6430-Aug-20 15:03 
GeneralRe: find TIMES in string of text Pin
free-pizza30-Aug-20 16:26
free-pizza30-Aug-20 16:26 
AnswerRe: find TIMES in string of text Pin
OriginalGriff30-Aug-20 19:47
mveOriginalGriff30-Aug-20 19:47 
JokeRe: find TIMES in string of text Pin
Peter_in_278030-Aug-20 19:59
professionalPeter_in_278030-Aug-20 19:59 
GeneralRe: find TIMES in string of text Pin
OriginalGriff30-Aug-20 20:08
mveOriginalGriff30-Aug-20 20:08 
GeneralRe: find TIMES in string of text Pin
OriginalGriff30-Aug-20 20:11
mveOriginalGriff30-Aug-20 20:11 
GeneralRe: find TIMES in string of text Pin
Peter_in_278030-Aug-20 20:43
professionalPeter_in_278030-Aug-20 20:43 
GeneralRe: find TIMES in string of text Pin
free-pizza31-Aug-20 3:52
free-pizza31-Aug-20 3:52 
GeneralRe: find TIMES in string of text Pin
OriginalGriff31-Aug-20 4:08
mveOriginalGriff31-Aug-20 4:08 
QuestionWinforms Inherited form - Resources Pin
MarkB12327-Aug-20 1:19
MarkB12327-Aug-20 1:19 
AnswerRe: Winforms Inherited form - Resources Pin
GenJerDan27-Aug-20 1:50
GenJerDan27-Aug-20 1:50 
GeneralRe: Winforms Inherited form - Resources Pin
MarkB12327-Aug-20 1:51
MarkB12327-Aug-20 1:51 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.