Click here to Skip to main content
15,889,877 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
Required: I want an xml file to be searialized like this

XML
<StudentGroupList>
   <Group key = 1>
      <StudentItem>
           <Name> John </Name>
           <GroupName>1</GroupName>
      <StudentItem>
      <StudentItem>
           <Name> David</Name>
           <GroupName>1</GroupName>
      <StudentItem>
   </Group>
   <Group key = 2>
      <StudentItem>
           <Name> Ron</Name>
           <GroupName>2</GroupName>
      <StudentItem>
   </Group>
 </StudentGroupList>


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.


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

1 solution

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.
 
Share this answer
 
Comments
Prateek Kumar Pradeep Srivastava 23-Nov-12 22:26pm    
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.
Prateek Kumar Pradeep Srivastava 24-Nov-12 14:05pm    
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)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900