Hi guys,
I have a class employees.
I have one generic class <tkey,tdata>
I have one dictionary <tkey,tdata>
I want to store the Employee info to a file.
After saving the object of Employees to Tdata (value) of dictionary, I cannot get the info of employee (firstname, lastname...) from dictionary in order to create a xml file.
Any idea to cast the value of dictionary to Employee to get the properties of employee class?
I can get the object of Employee by a foreach(var item in dictionary) => item.Value
but I cannot cast to get the properties of the employee class!
Thank you!
======code
Main Class:
EmployeeMNG<string,employees> empMNG= new EmployeeMNG<string,employees>();
Employees s= new Employees();
s.empNo = 11;
s.firstName = "khoaxml";
s.lastName = "nguyen";
s.address = "47 nguyen hong";
s.country = "VN";
empMNG.add("stu", s); empMNG.save("file.xml");
Generic Class:
public class EmpMNG<tkey,tdata> : IEmpMNG<<tkey,tdata>
{
private Dictionary<tkey,tdata> cache;
public EmpMNG()
{
cache = new Dictionary<tkey,tdata>();
}
public TData add(TKey key, TData data)
{
if (!cache.ContainsKey(key))
{
cache[key] = data;
}
return cache[key];
}
public void Save(string xmlPath)
{
foreach (var item in cache)
{
Console.WriteLine(item.Value);
}
}