[2.0] Problems with Generic Collection class.
Hi I’m working on a system that has 4 different types of client they have mostly the same attributes so I decided to create an interface IClient for them to implement and then just add the differing attributes as needed to each client class.
Now I get the Client information from a DB and Load them into a Generic dictionary
The class looks like so
Code:
class Class1<T> : Dictionary<int, T> where T:IClient
{
private IndemnityScheme scheme;
public Class1(IndemnityScheme scheme)
{
this.scheme = scheme;
}
public int Load()
{
// "procIndemnityClientSelect";
DataBaseAccess dba = new DataBaseAccess(this.scheme);
SqlDataReader reader = dba.LoadData("procPrsymClientSelect");
SmartDataReader smartReader = new SmartDataReader(reader);
while (smartReader.Read()) {
AceClient newClient = new AceClient(this.scheme);
newClient.Clientshort = smartReader.GetString("Client Short Name");
newClient.Clientname = smartReader.GetString("Client Name");
newClient.Clientref = smartReader.GetInt32("client ref");
newClient.AddressLine1 = smartReader.GetString("Address Line 1");
newClient.AddressLine2 = smartReader.GetString("Address Line 2");
newClient.AddressLine3 = smartReader.GetString("Address Line 3");
newClient.AddressLine4 = smartReader.GetString("Address Line 4");
newClient.AddressLine5 = smartReader.GetString("Address Line 5");
newClient.AddressLine6 = smartReader.GetString("Address Line 6");
newClient.Telephone = smartReader.GetString("Telephone No");
newClient.PostCode = smartReader.GetString("post code");
newClient.Contact = smartReader.GetString("Contact");
// newClient.Handler = smartReader.GetString("Handler");
newClient.Joindate = smartReader.GetString("Join Date");
newClient.Leavingdate = smartReader.GetString("leaving Date");
newClient.Salutation = smartReader.GetString("salutation");
newClient.Email = smartReader.GetString("Email");
newClient.Comments = smartReader.GetString("comments");
base.Add(newClient.Clientref, newClient);
}
smartReader.Close();
smartReader = null;
dba = null;
return base.Count;
}
}
I call the class in my program like so
Code:
AceClient c = new AceClient(IndemnityScheme.ACE);
Class1<AceClient> cl = new Class1<AceClient>(IndemnityScheme.ACE);
cl.Load();
foreach (AceClient ac in cl.Values) {
System.Diagnostics.Debug.WriteLine(ac.Clientshort);
}
Nothing fancy just want to loop throught the collection but on trying to complie I get an error.
This is the line of code that errors
Code:
base.Add(newClient.Clientref, newClient);
Error 24 The best overloaded method match for 'System.Collections.Generic.Dictionary<int,T>.Add(int, T)' has some invalid arguments
Error 25 Argument '2': cannot convert from 'Prsym.AceClient' to 'T'
Can anyone tell me what I am doing wrong??