© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•3y 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>>(),
};
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?
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

❔ How to deserialize correctly
C#CC# / help
4y ago
❔ How to correctly use Roslyn to parse RegionDirectiveTriviaSyntax in a project?
C#CC# / help
3y ago
❔ How to shorten switch statement
C#CC# / help
3y ago
❔ How to make categories correctly?
C#CC# / help
4y ago