Click here to Skip to main content
12,945,066 members (50,296 online)
Rate this:
Please Sign up or sign in to vote.
See more:
Required: I want an xml file to be searialized like this

   <Group key = 1>
           <Name> John </Name>
           <Name> David</Name>
   <Group key = 2>
           <Name> Ron</Name>

Here is the class structure i created to serialize and desreialize

public class StudentItem
   public string Name {get; set;}
   public  int GroupName {get; set;}
public class StudentGroupList
   public List<StudentItem> lstStudnetItem = new List<StudentItem>(){get;set;}
   int key {get;set;}
public class StudentDataSource
       public List<StudentGroupList> lstStudnetGroup = new List<StudentGroupList>()   {get;set;}
      //Confusion in below line
      public static StudentDataSource objDataSource = new  StudentDataSource();

i have created single instance of StudentDataSource so that i can use it globally on every page of my windwos 8 aap. i want to use single instance because this instance will desrialize from the xml file above and simultaneously update it as soon as any changes are made. Now as u see i have made this instance as static i can't access the "lstStudnetGroup".
Please provide me a solution of class structure so that i can easily create an aap.

please forgive my representation, its the first time i am writing on any blog for help.
Posted 22-Nov-12 22:17pm
Updated 23-Nov-12 16:26pm

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Firstly this has nothing to do with Windows 8, it is purely a C# issue. Your class variables all have private visibility so cannot be seen outside of their classes. Add the public keyword to them and try again.
i made the changes in code. still it doesn't work.
and obviously how will it work sir, a static object "objDataSource " can't access a non static object "lstStudnetGroup"
any solution to it?
Richard MacCutchan 24-Nov-12 5:13am
Well I guess using a static element in this way is not a good design.
so please suggest me something else
Richard MacCutchan 25-Nov-12 3:04am
Why do you need a static object in the first place? Re-design your program so it only creates one instance of the list and fills it from the XML source at the beginning and serialises it at some other point.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

    Print Answers RSS
Top Experts
Last 24hrsThis month
OriginalGriff 4,651
CHill60 3,055
Maciej Los 2,423
Jochen Arndt 1,910
ppolymorphe 1,765

Advertise | Privacy | Mobile
Web02 | 2.8.170518.1 | Last Updated 23 Nov 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100