I have a cache class which stores a list into a dictionary:
public class CacheList<T>
{
private Dictionary<UInt64, T> _cacheItems = new Dictionary<UInt64, T>();
public IList<T> GetItems()
{
return new List<T>(_cacheItems.Values);
}
public void Add(T item)
{
UInt64 key = (UInt64)(item.GetHashCode());
if (!_cacheItems.ContainsKey(key))
_cacheItems.Add(key, item);
}
}
Now I am adding items to the dictionary by getting the Hashcode from the generic T. But I would like to specify which field / property I want to have as the key. Problem is it is a type T so it doesn’t know which properties are in this item.
How would I access a property from a generic item?
Maybe:
Then: