I have the following method in an external class
public static void DoStuffWithAnimals(IDictionary animals)
In my cal
Solution wise you could do something like this, just pass in an accessor instead:
public static void DoStuffWithAnimals(Func getAnimal)
{
}
var dicLions = new Dictionary();
DoStuffWithAnimals(s => dicLions[s]);
Obviously that is likely to be a bit simple for your needs, but if you only need a couple of the dictionary methods it's pretty easy to get that in place.
This is another way that gives you a bit of code re-use between your animals:
public class Accessor : IAnimalAccessor where T : Animal
{
private readonly Dictionary _dict;
public Accessor(Dictionary dict)
{
_dict = dict;
}
public Animal GetItem(String key)
{
return _dict[key];
}
}
public interface IAnimalAccessor
{
Animal GetItem(string key);
}
public static void DoStuffWithAnimals(IAnimalAccessor getAnimal)
{
}
var dicLions = new Dictionary();
var accessor = new Accessor(dicLions);
DoStuffWithAnimals(accessor);