I am trying to create a custom KeyCollection that will only allow my
domain objects to be added to the Collection. I was hoping I could
achieve the following implementation.
GenericKeyedCol lection<int, Person> collection = new
GenericKeyedCol lection<int, Person>();
Person person1 = new Person();
person1.ID = 1;
person1.Name = "Jimmy";
Person person2 = new Person();
person2.ID = 2;
person2.Name = "Chris";
collection.Add( person1);
collection.Add( person2);
Assert.AreEqual (2, collection.Coun t);
Now I thought I understood how to do this but I don't know what to
put in the absratct protected override GetKeyForItem. Can someone
please give me some guidance on what to put here?
Here is my implmentation of the GenericKeyedCol lection.
using System;
using System.Collecti ons.Generic;
using System.Collecti ons.ObjectModel ;
using System.Text;
namespace Unity.Domain
{
public class GenericKeyedCol lection<Key, Type> :
KeyedCollection <Key,
Type>
{
protected override Key GetKeyForItem(T ype item)
{
//What do I put here since at runtime
//I don't know what the
type will be?
}
}
domain objects to be added to the Collection. I was hoping I could
achieve the following implementation.
GenericKeyedCol lection<int, Person> collection = new
GenericKeyedCol lection<int, Person>();
Person person1 = new Person();
person1.ID = 1;
person1.Name = "Jimmy";
Person person2 = new Person();
person2.ID = 2;
person2.Name = "Chris";
collection.Add( person1);
collection.Add( person2);
Assert.AreEqual (2, collection.Coun t);
Now I thought I understood how to do this but I don't know what to
put in the absratct protected override GetKeyForItem. Can someone
please give me some guidance on what to put here?
Here is my implmentation of the GenericKeyedCol lection.
using System;
using System.Collecti ons.Generic;
using System.Collecti ons.ObjectModel ;
using System.Text;
namespace Unity.Domain
{
public class GenericKeyedCol lection<Key, Type> :
KeyedCollection <Key,
Type>
{
protected override Key GetKeyForItem(T ype item)
{
//What do I put here since at runtime
//I don't know what the
type will be?
}
}
Comment