C
C#5mo ago
TOKYODRIFT!

✅ 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>>(),
};
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?
0 Replies
No replies yetBe the first to reply to this messageJoin