@@ -8,63 +8,56 @@ namespace Aspose.Cells.Examples.CSharp.SmartMarkers
88{
99 public class UsingGenericList
1010 {
11-
12- public class Husband
13- {
14- private String m_Name;
15-
16- public String Name
17- {
18- get { return m_Name; }
19- set { m_Name = value; }
20- }
21-
22- private int m_Age;
2311
12+ public class Person
13+ {
14+ int _age;
15+ string _name;
2416 public int Age
2517 {
26- get { return m_Age; }
27- set { m_Age = value; }
18+ get
19+ {
20+ return _age;
21+ }
22+ set
23+ {
24+ _age = value;
25+ }
2826 }
29-
30- internal Husband(string name, int age)
27+ public string Name
3128 {
32- this.Name = name;
33- this.Age = age;
29+ get
30+ {
31+ return _name;
32+ }
33+ set
34+ {
35+ _name = value;
36+ }
3437 }
3538
36- // Accepting a generic List as a Nested Object
37- private List<Wife> m_Wives;
38-
39- public List<Wife> Wives
39+ public Person(string name, int age)
4040 {
41- get { return m_Wives; }
42- set { m_Wives = value; }
41+ _age = age;
42+ _name = name;
4343 }
44-
44+ // ExEnd:1
4545 }
4646
47- public class Wife
47+ public class Teacher : Person
4848 {
49- public Wife(string name, int age)
50- {
51- this.m_name = name;
52- this.m_age = age;
53- }
5449
55- private string m_name;
5650
57- public string Name
51+ public Teacher( string name, int age) : base(name, age)
5852 {
59- get { return m_name; }
60- set { m_name = value; }
53+ m_students = new List<Person>();
6154 }
62- private int m_age ;
55+ private IList<Person> m_students ;
6356
64- public int Age
57+ public IList<Person> Students
6558 {
66- get { return m_age ; }
67- set { m_age = value; }
59+ get { return m_students ; }
60+ set { m_students = value; }
6861 }
6962 }
7063
@@ -74,23 +67,23 @@ public static void Run()
7467 // The path to the documents directory.
7568 string dataDir = RunExamples.GetDataDir(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
7669 Workbook workbook = new Workbook();
77-
70+
7871 // Create a designer workbook
7972
8073 // Workbook workbook = new Workbook();
8174 Worksheet worksheet = workbook.Worksheets[0];
8275
83- worksheet.Cells["A1"].PutValue("Husband Name");
84- worksheet.Cells["A2"].PutValue("&=Husband .Name");
76+ worksheet.Cells["A1"].PutValue("Teacher Name");
77+ worksheet.Cells["A2"].PutValue("&=Teacher .Name");
8578
86- worksheet.Cells["B1"].PutValue("Husband Age");
87- worksheet.Cells["B2"].PutValue("&=Husband .Age");
79+ worksheet.Cells["B1"].PutValue("Teacher Age");
80+ worksheet.Cells["B2"].PutValue("&=Teacher .Age");
8881
89- worksheet.Cells["C1"].PutValue("Wife's Name");
90- worksheet.Cells["C2"].PutValue("&=Husband.Wives .Name");
82+ worksheet.Cells["C1"].PutValue("Student Name");
83+ worksheet.Cells["C2"].PutValue("&=Teacher.Students .Name");
9184
92- worksheet.Cells["D1"].PutValue("Wife's Age");
93- worksheet.Cells["D2"].PutValue("&=Husband.Wives .Age");
85+ worksheet.Cells["D1"].PutValue("Student Age");
86+ worksheet.Cells["D2"].PutValue("&=Teacher.Students .Age");
9487
9588 // Apply Style to A1:D1
9689 Range range = worksheet.Cells.CreateRange("A1:D1");
@@ -108,32 +101,32 @@ public static void Run()
108101 // Load the template file
109102 designer.Workbook = workbook;
110103
111- System.Collections.Generic.List<Husband > list = new System.Collections.Generic.List<Husband >();
104+ System.Collections.Generic.List<Teacher > list = new System.Collections.Generic.List<Teacher >();
112105
113- // Create an object for the Husband class
114- Husband h1 = new Husband ("Mark John", 30);
106+ // Create an object for the Teacher class
107+ Teacher h1 = new Teacher ("Mark John", 30);
115108
116- // Create the relevant Wife objects for the Husband object
117- h1.Wives = new List<Wife >();
118- h1.Wives .Add(new Wife ("Chen Zhao", 34 ));
119- h1.Wives .Add(new Wife ("Jamima Winfrey", 28 ));
120- h1.Wives .Add(new Wife ("Reham Smith", 35 ));
109+ // Create the relevant student objects for the Teacher object
110+ h1.Students = new List<Person >();
111+ h1.Students .Add(new Person ("Chen Zhao", 14 ));
112+ h1.Students .Add(new Person ("Jamima Winfrey", 18 ));
113+ h1.Students .Add(new Person ("Reham Smith", 15 ));
121114
122- // Create another object for the Husband class
123- Husband h2 = new Husband ("Masood Shankar", 40);
115+ // Create another object for the Teacher class
116+ Teacher h2 = new Teacher ("Masood Shankar", 40);
124117
125- // Create the relevant Wife objects for the Husband object
126- h2.Wives = new List<Wife >();
127- h2.Wives .Add(new Wife ("Karishma Jathool", 36 ));
128- h2.Wives .Add(new Wife ("Angela Rose", 33 ));
129- h2.Wives .Add(new Wife ("Hina Khanna", 45 ));
118+ // Create the relevant student objects for the Teacher object
119+ h2.Students = new List<Person >();
120+ h2.Students .Add(new Person ("Karishma Jathool", 16 ));
121+ h2.Students .Add(new Person ("Angela Rose", 13 ));
122+ h2.Students .Add(new Person ("Hina Khanna", 15 ));
130123
131124 // Add the objects to the list
132125 list.Add(h1);
133126 list.Add(h2);
134127
135128 // Specify the DataSource
136- designer.SetDataSource("Husband ", list);
129+ designer.SetDataSource("Teacher ", list);
137130
138131 // Process the markers
139132 designer.Process();
0 commit comments