C#C
C#2y ago
SWEETPONY

✅ How to use switch correctly?

I have following:
var rootRepositoryTest = pureCommand.BaseType?.GetGenericTypeDefinition() switch
{
     var t when t == typeof(ReadModelPureCommand<>) => scope.ServiceProvider.GetService<ReadModelRootRepository<EventHandlingContext>>(),
     var t when t == typeof(ResourceManagerPureCommand<>) => scope.ServiceProvider.GetService<ResourceManagerRootRepository<ExecutionEventHandlingContext>>(),
};


and I have error in switch: Cannot find best common type for types {ReadModelRootRepository<EventHandlingContext>?,ResourceManagerRootRepository<ExecutionEventHandlingContext>?}
what should I do?
Was this page helpful?