You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Feature Request: Support for Open Generic TypeHandler registration #2190
Currently, Dapper does not support registering open generic types for TypeHandler.
This creates a significant maintenance burden and forces developers to violate the DRY principle.
I have a generic TypeHandler that works perfectly for any T, for example, handling HashSet for PostgreSQL arrays:
publicclassHashSetHandler<T>:SqlMapper.TypeHandler<HashSet<T>>{publicoverridevoidSetValue(IDbDataParameterparameter,HashSet<T>value){// Solves Npgsql issue with IEnumerable parametersparameter.Value=value?.ToArray();}publicoverrideHashSet<T>Parse(objectvalue){if(valueisT[]array){returnnewHashSet<T>(array);}returnnewHashSet<T>();}}
To use this handler, I am forced to manually register every single closed generic type variation used in the application. This is tedious, error-prone, and clutters the startup configuration:
SqlMapper.AddTypeHandler(newHashSetHandler<Guid>());SqlMapper.AddTypeHandler(newHashSetHandler<int>());SqlMapper.AddTypeHandler(newHashSetHandler<string>());SqlMapper.AddTypeHandler(newHashSetHandler<MyEnum>());// ... repeated for every new type added to the domain models
Please allow the registration of open generic handlers. Dapper should be able to resolve the concrete handler at runtime if an open generic definition is registered.
Right said! It will be great to register types at once rather than explicitly specifying types in the application. I can pick this up and open a PR when done. I just need this to be validated by the maintainer and I can work out a fix for it
Activity
classyk12 commentedon May 15, 2026
Right said! It will be great to register types at once rather than explicitly specifying types in the application. I can pick this up and open a PR when done. I just need this to be validated by the maintainer and I can work out a fix for it