This project is read-only.
Project Description
A project that will offer an alternative to the generic KeyedCollection<key, item> for ease of use.

I'm a fan of the KeyedCollection. Simply because it resembles how a table in database works... in a simple way. The Objects in the collection contains their key values. This makes it a good candidate for caching and handling business data in memory in a database like manner.

However a few thing are annoying when dealing with the KeyedCollection: It's abstract, so you'll have to make an implementation to use it, and unlike tables from a database you can use only one value as your key.

The Primary Objective of the KeyedList project is to make a more easy-to-use version of the Generic KeyedCollection.

Example:
KeyedList<string, MyClass> list = new KeyedList<string, MyClass>();
if(list.Contains("key"))
{
   MyClass item = list["key"];
}

The KeyedCollection is abstract and requires an implementation to work, more specific you have to provide a method GetKeyForItem() that will provide a key for the KeyedCollection for the items in the list.

The KeyedList is in fact an implementation of the KeyedCollection, but it offers three altenate ways to let the user provide keys for the chosen item.

1. By passing in a delegate on instantiation
KeyedList<string, MyClass> list = new KeyedList<string, MyClass>(x => x.KeyValue);

2. Implemting an interface on the target Class
class MyClass : IKeyedItem<string>
{
   string IKeyedItem<string>.Key
   {
      get { return this.KeyValue; }
   }
}
KeyedList<string, MyClass> list = new KeyedList<string, MyClass>();
// ect.. 

3. Or by decorating the Property that defines the key with an DataObjectField attribute.
class MyClass : IKeyedItem<string>
{
	[DataObjectField(true)]
	public string KeyValue { get; set; }
}
KeyedList<string, MyClass> list = new KeyedList<string, MyClass>();
// ect.. 



The Second Objective is to add handling of a combination of values as a key for the internal dictionary.

Example here by using a combination of int and string Types
KeyedList<int, string, MyClass> list = new KeyedList<int, string, MyClass>();
if(list.Contains(2, "key"))
{   
    MyClass item = list[2,"key"];
}
//  ect ...


Last edited Sep 25, 2008 at 9:37 AM by manicpengo, version 8