Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: Deserialize
Hi,
Required: I want an xml file to be searialized like this
 
<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 22-Nov-12 22:17pm
Edited 23-Nov-12 16:26pm
v4

1 solution

Rate this: bad
good
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.
  Permalink  
Comments
Prateek Kumar Pradeep Srivastava at 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 at 24-Nov-12 5:13am
   
Well I guess using a static element in this way is not a good design.
Prateek Kumar Pradeep Srivastava at 24-Nov-12 14:05pm
   
so please suggest me something else
Richard MacCutchan at 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
0 Sergey Alexandrovich Kryukov 309
1 Richard MacCutchan 295
2 OriginalGriff 270
3 Sharmanuj 146
4 Magic Wonder 129
0 Sergey Alexandrovich Kryukov 5,969
1 OriginalGriff 5,005
2 CPallini 2,473
3 Richard MacCutchan 1,547
4 Abhinav S 1,507


Advertise | Privacy | Mobile
Web03 | 2.8.140814.1 | Last Updated 23 Nov 2012
Copyright © CodeProject, 1999-2014
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