I have method like this:
public static void Raise<TEvent>(TEvent eventToRaise)
where TEvent : IEvent
{
}
And I call that method like this:
foreach (IEvent evt in entity.UncommittedEvents)
{
DomainEvents.Raise(evt);
}
where I assume that this is true:
bool areSame = typeof(TEvent) == eventToRaise.GetType();
but it seems that it is not true. Instead it is:
bool areSame = typeof(TEvent) == typeof(IEvent);
Why is that so?
Problem here is that I “lost” type of concrete event here. When I pass that type parameter to next method (without instance of event) I have only type “IEvent”….
Use runtime type definition (
dynamictype) otherwise generic parameter type will beIEvent(inferred from parameter type at compile time):