Help in creating a collection class

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Matthew Hood

    #1

    Help in creating a collection class

    Here's the situation.
    I am developing an ASP.NET web application. Most of my forms will be
    accessing a database (MS Access) for either record
    creation/deletion/updating or for list lookups. The problem I have is my
    boss constantly wants to revise table and field names and I am the one that
    has to make sure everthing works after the fact. What I want to do is
    create 2 classes.

    The first one is my "Record" wrapper class that will map to the table field
    names. This is to provide me a consistant interface so when the database
    field name is changed, all I have to do is change the field mapping in this
    class.

    The second class is my "Records" collection. I can create the database
    methods myself, but I need to be able to set the rest of the interface up
    and this is where I get a little confused. There are several different
    collection objects available: array, arraylist, collection, dictionary...
    I'm not sure what the best method is and how to go about implementing it.
    What are your recomendations for this? I was able to do this easily in VB6,
    but I'm not sure how to do it in .NET

    1: I need to be able to use For Each Next... syntax
    2: I need to be able to use either the Collection(Inde x as Integer) or
    Collection(KeyN ame as String) methods to access an item.
    3: I need to be able to strict types. Collection.Add( CollectionItem as
    MyType)
    4: Sorting is not needed. I will accomplish this in my SQL string.
    4: Performance is an issue, but ease of use and functionality is a higher
    priority.

    Can anybody help explain what I need to do, and/or point me to some good
    examples on the web where I can learn how to do it?

    TIA,
    -Matt


  • Gang Peng

    #2
    Re: Help in creating a collection class

    In your case, you can simply implement IEnumerable on your class, which will
    alow you to use For Each.
    You can use add index methods on your class to support 2.
    Just add Add((Collection Item as MyType) method on your class, you will have
    all you need.
    You could also implement System.Collecti ons.IList on your class, but this
    interface contains many methods you might not want to implement.
    The advantage of implement IList is that you can use your collection on many
    framework methods, which might not be important for you.

    You can look at the implementation of StringCollectio n class in .Net
    Framework (download rotor source and go to
    fx\src\compmod\ system\collecti ons\specialized .)
    Or down a strong-typed collection sample from


    Hope this helps,
    Gang Peng
    [MS]

    "Matthew Hood" <mshood@qwest.n et> wrote in message
    news:ucd89BzPDH A.304@tk2msftng p13.phx.gbl...[color=blue]
    > Here's the situation.
    > I am developing an ASP.NET web application. Most of my forms will be
    > accessing a database (MS Access) for either record
    > creation/deletion/updating or for list lookups. The problem I have is my
    > boss constantly wants to revise table and field names and I am the one[/color]
    that[color=blue]
    > has to make sure everthing works after the fact. What I want to do is
    > create 2 classes.
    >
    > The first one is my "Record" wrapper class that will map to the table[/color]
    field[color=blue]
    > names. This is to provide me a consistant interface so when the database
    > field name is changed, all I have to do is change the field mapping in[/color]
    this[color=blue]
    > class.
    >
    > The second class is my "Records" collection. I can create the database
    > methods myself, but I need to be able to set the rest of the interface up
    > and this is where I get a little confused. There are several different
    > collection objects available: array, arraylist, collection, dictionary...
    > I'm not sure what the best method is and how to go about implementing it.
    > What are your recomendations for this? I was able to do this easily in[/color]
    VB6,[color=blue]
    > but I'm not sure how to do it in .NET
    >
    > 1: I need to be able to use For Each Next... syntax
    > 2: I need to be able to use either the Collection(Inde x as Integer) or
    > Collection(KeyN ame as String) methods to access an item.
    > 3: I need to be able to strict types. Collection.Add( CollectionItem as
    > MyType)
    > 4: Sorting is not needed. I will accomplish this in my SQL string.
    > 4: Performance is an issue, but ease of use and functionality is a higher
    > priority.
    >
    > Can anybody help explain what I need to do, and/or point me to some good
    > examples on the web where I can learn how to do it?
    >
    > TIA,
    > -Matt
    >
    >[/color]


    Comment

    Working...