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
class Class1<T: Dictionary<int, Twhere T:IClient
{
private IndemnityScheme scheme;
public Class1(Indemnit yScheme scheme)
{
this.scheme = scheme;
}
public int Load()
{
// "procIndemnityC lientSelect";
DataBaseAccess dba = new DataBaseAccess( this.scheme);
SqlDataReader reader =
dba.LoadData("p rocPrsymClientS elect");
SmartDataReader smartReader = new SmartDataReader (reader);
while (smartReader.Re ad()) {
AceClient newClient = new AceClient(this. scheme);
newClient.Clien tshort = smartReader.Get String("Client
Short Name");
newClient.Clien tname = smartReader.Get String("Client
Name");
newClient.Clien tref = smartReader.Get Int32("client
ref");
newClient.Addre ssLine1 = smartReader.Get String("Address
Line 1");
newClient.Addre ssLine2 = smartReader.Get String("Address
Line 2");
newClient.Addre ssLine3 = smartReader.Get String("Address
Line 3");
newClient.Addre ssLine4 = smartReader.Get String("Address
Line 4");
newClient.Addre ssLine5 = smartReader.Get String("Address
Line 5");
newClient.Addre ssLine6 = smartReader.Get String("Address
Line 6");
newClient.Telep hone = smartReader.Get String("Telepho ne
No");
newClient.PostC ode = smartReader.Get String("post
code");
newClient.Conta ct = smartReader.Get String("Contact ");
// newClient.Handl er = smartReader.Get String("Handler ");
newClient.Joind ate = smartReader.Get String("Join
Date");
newClient.Leavi ngdate = smartReader.Get String("leaving
Date");
newClient.Salut ation =
smartReader.Get String("salutat ion");
newClient.Email = smartReader.Get String("Email") ;
newClient.Comme nts = smartReader.Get String("comment s");
base.Add(newCli ent.Clientref, newClient);
}
smartReader.Clo se();
smartReader = null;
dba = null;
return base.Count;
}
}
I call the class in my program like so
AceClient c = new AceClient(Indem nityScheme.ACE) ;
Class1<AceClien tcl = new
Class1<AceClien t>(IndemnitySch eme.ACE);
cl.Load();
foreach (AceClient ac in cl.Values) {
System.Diagnost ics.Debug.Write Line(ac.Clients hort);
}
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
base.Add(newCli ent.Clientref, newClient);
Error 24 The best overloaded method match for
'System.Collect ions.Generic.Di ctionary<int,T> .Add(int, T)' has some
invalid arguments
Error 25 Argument '2': cannot convert from 'Prsym.AceClien t'
to 'T'
Can anyone tell me what I am doing wrong??