Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Problems with Generic Collection class.

Problems with Generic Collection class.

Scheduled Pinned Locked Moved C#
database
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    burrows stephen
    wrote on last edited by
    #1

    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();

    P 1 Reply Last reply
    0
    • B burrows stephen

      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();

      P Offline
      P Offline
      Pete OHanlon
      wrote on last edited by
      #2

      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.

      B 1 Reply Last reply
      0
      • P Pete OHanlon

        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.

        B Offline
        B Offline
        burrows stephen
        wrote on last edited by
        #3

        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

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups