我有以下课程
public class CVisitor : IVisitor
{
public int Visit(Heartbeat element)
{
Trace.WriteLine("Heartbeat");
return 1;
}
public int Visit(Information element)
{
Trace.WriteLine("Information");
return 1;
}
}
我想要一个带有映射的字典,每个参数类型都将映射到它的实现函数:Heartbeat 将映射到public int Visit(Heartbeat element)
我想做类似以下的事情:
_messageMapper = new Dictionary<Type, "what should be here ?" >();
_messageMapper.Add(typeof(Heartbeat), "and how I put it here?" );
我应该用什么代替“这里应该有什么?”以及“我怎么把它放在这里?”
Thanks
new Dictionary<Type, Func<object, int>>();
var cVisitor = new CVisitor();
_messageMapper.Add(typeof(Heartbeat),
new Func<object, int>(heartbeat => cVisitor.Visit((Heartbeat)heartbeat))
);
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)