得到以下代码
protected virtual void InternalChange(DomainEvent @event)
{
((dynamic) this).Apply(@event);
}
子对象通过多个字段实现处理事件的逻辑,例如
protected Apply ( Message1 message)
{
}
protected Apply ( Message2 message)
{
}
然而,这给出了一个错误,说它无法访问。我尝试了虚拟但没有运气..
有任何想法吗 ?..希望没有像这种方法那样的反思。(例如http://blogs.msdn.com/b/davidebb/archive/2010/01/18/use-c-4-0-dynamic-to-drastical-simplify-your-private-reflection-code.aspx)
更多信息我可以将 InternalChange 移动到子类,但 id 而不是让孩子进行调度。
void Apply(AggregateRootHandlerThatMeetsConventionEvent domainEvent)
{
OnAggregateRootPrivateHandlerThatMeetsConventionCalled = true;
}
void Apply(AggregateRootPrivateHandlerThatMeetsConventionEvent domainEvent)
{
OnAggregateRootPrivateHandlerThatMeetsConventionCalled = true;
}
void Apply(AggregateRootProtectedHandlerThatMeetsConventionEvent domainEvent)
{
OnAggregateRootProtectedHandlerThatMeetsConventionCalled = true;
}
protected override void InternalChange(DomainEvent @event)
{
Apply(((dynamic)@event));
}
现在编辑我在孩子中使用它(并使父抽象),它可以工作,但它的丑陋 id 而不是实现者不用担心调度。
protected void Handle(DomainEvent message)
{
Handle ( (dynamic) message);
}