Generic A* implementation in C#