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 : Dictionary 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();
-
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 : Dictionary 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();
Does AceClient implement the IClient interface? This error can occur because the class violates the conditions of the generic (in this case where T implements IClient).
the last thing I want to see is some pasty-faced geek with skin so pale that it's almost translucent trying to bump parts with a partner - John Simmons / outlaw programmer
Deja View - the feeling that you've seen this post before. -
Does AceClient implement the IClient interface? This error can occur because the class violates the conditions of the generic (in this case where T implements IClient).
the last thing I want to see is some pasty-faced geek with skin so pale that it's almost translucent trying to bump parts with a partner - John Simmons / outlaw programmer
Deja View - the feeling that you've seen this post before.Thanks for the reply yes the AceCLient does Implement ICleint. I was hoping that class Class1 : Dictionary where T:IClient would mean the Dictionary Type would be of the Type of the instantiate calls so in my instanace the dictionary would be Dictionary : Dictionary where T:IClient It just means if i wish to access the collection by a class that implements ICLient i have to do the following casting ((AceClient)col[1]).Temp; where col is the collection and Temp is and exdened property of AceCLient Not found in IClient