Click here to Skip to main content
15,895,370 members
Home / Discussions / C#
   

C#

 
GeneralRe: XML Serialization of ArrayList? [modified] Pin
Software200714-Dec-10 13:56
Software200714-Dec-10 13:56 
AnswerRe: XML Serialization of ArrayList? Pin
Hiren solanki14-Dec-10 19:45
Hiren solanki14-Dec-10 19:45 
GeneralRe: XML Serialization of ArrayList? Pin
Software200715-Dec-10 2:52
Software200715-Dec-10 2:52 
AnswerRe: XML Serialization of ArrayList? Pin
Hiren solanki15-Dec-10 2:58
Hiren solanki15-Dec-10 2:58 
GeneralRe: XML Serialization of ArrayList? Pin
Henry Minute15-Dec-10 2:26
Henry Minute15-Dec-10 2:26 
GeneralRe: XML Serialization of ArrayList? [modified] Pin
Software200715-Dec-10 2:55
Software200715-Dec-10 2:55 
GeneralMessage Removed Pin
15-Dec-10 3:20
Software200715-Dec-10 3:20 
GeneralRe: XML Serialization of ArrayList? Pin
Henry Minute15-Dec-10 3:29
Henry Minute15-Dec-10 3:29 
C#
public class Program
{
    [Serializable]
    public class person
    {
        public person()
        {
            ;
        }  //default constructor
        public string firstname;
        public string lastname;
        public int Age;

    }

    [
    XmlInclude(typeof(person))
    ]
    public class persons
    {
        public persons()
        {
        }

        public ArrayList personlist = new ArrayList();
    }

    [STAThread]
    static void Main()
    {
        Application.EnableVisualStyles();
        Application.SetCompatibleTextRenderingDefault(false);
        //Application.Run(new Form1());


        person p = new person();

        p.firstname = "Tim";
        p.lastname = "Duncan";
        p.Age = 34;

        persons ps = new persons();
        ps.personlist.Add(p);

        FileStream fs = File.Create("C:\\Temp\\test.xml");

        XmlSerializer xs = new XmlSerializer(typeof(persons));
        xs.Serialize(fs, ps);

    }
}


The List<whatever> solution works because a generic List is strongly typed. It returns an instance of a 'whatever' when you index into it. ArrayList however, returns an instance of Object and the serialization code cannot, for whatever reason, resolve the object into a person.

Using XmlInclude, very rough potted explanation here Smile | :) , says "Hey I'm using instances of person in here somewhere, so if you find something you can't resolve, try person before bombing out."

Hope this helps.
Henry Minute

Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”

GeneralRe: XML Serialization of ArrayList? Pin
Software200715-Dec-10 3:46
Software200715-Dec-10 3:46 
GeneralRe: XML Serialization of ArrayList? Pin
Henry Minute15-Dec-10 3:52
Henry Minute15-Dec-10 3:52 
GeneralRe: XML Serialization of ArrayList? Pin
Software200715-Dec-10 3:58
Software200715-Dec-10 3:58 
QuestionUse a ComboBoxCell to update textboxcell on a Binded Datagridview Pin
olibara14-Dec-10 4:04
olibara14-Dec-10 4:04 
AnswerRe: Use a ComboBoxCell to update textboxcell on a Binded Datagridview Pin
Henry Minute14-Dec-10 5:40
Henry Minute14-Dec-10 5:40 
GeneralRe: Use a ComboBoxCell to update textboxcell on a Binded Datagridview Pin
olibara14-Dec-10 6:28
olibara14-Dec-10 6:28 
GeneralRe: Use a ComboBoxCell to update textboxcell on a Binded Datagridview Pin
Henry Minute14-Dec-10 7:10
Henry Minute14-Dec-10 7:10 
GeneralRe: Use a ComboBoxCell to update textboxcell on a Binded Datagridview Pin
Henry Minute14-Dec-10 7:58
Henry Minute14-Dec-10 7:58 
GeneralRe: Use a ComboBoxCell to update textboxcell on a Binded Datagridview Pin
olibara14-Dec-10 23:30
olibara14-Dec-10 23:30 
QuestionEvent for checking if a delegate/anonymous method result changed Pin
hoernchenmeister14-Dec-10 3:40
hoernchenmeister14-Dec-10 3:40 
AnswerRe: Event for checking if a delegate/anonymous method result changed Pin
Abhinav S14-Dec-10 5:14
Abhinav S14-Dec-10 5:14 
GeneralRe: Event for checking if a delegate/anonymous method result changed Pin
hoernchenmeister14-Dec-10 5:45
hoernchenmeister14-Dec-10 5:45 
AnswerRe: Event for checking if a delegate/anonymous method result changed Pin
Ian Shlasko14-Dec-10 5:25
Ian Shlasko14-Dec-10 5:25 
GeneralRe: Event for checking if a delegate/anonymous method result changed Pin
hoernchenmeister14-Dec-10 5:43
hoernchenmeister14-Dec-10 5:43 
GeneralRe: Event for checking if a delegate/anonymous method result changed Pin
Ian Shlasko14-Dec-10 6:07
Ian Shlasko14-Dec-10 6:07 
GeneralRe: Event for checking if a delegate/anonymous method result changed Pin
hoernchenmeister14-Dec-10 6:33
hoernchenmeister14-Dec-10 6:33 
GeneralRe: Event for checking if a delegate/anonymous method result changed Pin
Ian Shlasko14-Dec-10 7:30
Ian Shlasko14-Dec-10 7:30 

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.