Dapper.Contrib
Dapper.Contrib copied to clipboard
Access to static readonly ConcurrentDictionary in SqlMapperExtensions
How access to TypeTableName in Dapper.Contrib.Extensions.SqlMapperExtensions class using Reflection?
private static readonly ConcurrentDictionary<RuntimeTypeHandle, string> TypeTableName = new ConcurrentDictionary<RuntimeTypeHandle, string>();
Not cannot set null to SqlMapperExtensions.TableNameMapper because use TypeTableName
https://github.com/StackExchange/Dapper/blob/main/Dapper.Contrib/SqlMapperExtensions.cs#L280
```
Delegate[] delegados = Dapper.Contrib.Extensions.SqlMapperExtensions.TableNameMapper.GetInvocationList();
foreach (TableNameMapperDelegate delegateTableNameMapper in delegados)
Dapper.Contrib.Extensions.SqlMapperExtensions.TableNameMapper -= delegateTableNameMapper;
Delegate.RemoveAll(Dapper.Contrib.Extensions.SqlMapperExtensions.TableNameMapper, Dapper.Contrib.Extensions.SqlMapperExtensions.TableNameMapper);
Dapper.Contrib.Extensions.SqlMapperExtensions.TableNameMapper -= tableNameDelegate;
Dapper.Contrib.Extensions.SqlMapperExtensions.TableNameMapper = null;
Can we back up slightly to what you're trying to do? Generally speaking if you need to reflect Dapper and it's a valid use case, we have a gap in the API which we could potentially solve in other ways!
What are you trying to read or change?
I think this should work, but haven't tested it.
var typeTableName = typeof(SqlMapperExtensions)
.GetFields(BindingFlags.Static | BindingFlags.NonPublic)
.FirstOrDefault(field => field.Name == "TypeTableName")
.GetValue(null);