Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mark AddTypeHandlerImpl as obsolete and prevent lost updates via AddTypeHandler #2129

Merged
merged 7 commits into from
Oct 31, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
avoid additional local snapshot, now that we're synchronized
  • Loading branch information
mgravell committed Oct 31, 2024
commit ea273e0297a2af78c3802ed5629651181db7d6d8
5 changes: 2 additions & 3 deletions Dapper/SqlMapper.cs
Original file line number Diff line number Diff line change
@@ -390,10 +390,9 @@ private static void AddTypeHandlerCore(Type type, ITypeHandler? handler, bool cl
// the synchronize is just to prevent lost writes
lock (typeHandlersSyncLock)
{
var snapshot = typeHandlers;
if (snapshot.TryGetValue(type, out var oldValue) && handler == oldValue) return; // nothing to do
if (typeHandlers.TryGetValue(type, out var oldValue) && handler == oldValue) return; // nothing to do

var newCopy = clone ? new Dictionary<Type, ITypeHandler>(snapshot) : snapshot;
var newCopy = clone ? new Dictionary<Type, ITypeHandler>(typeHandlers) : typeHandlers;

#pragma warning disable 618
typeof(TypeHandlerCache<>).MakeGenericType(type).GetMethod(nameof(TypeHandlerCache<int>.SetHandler), BindingFlags.Static | BindingFlags.NonPublic)!.Invoke(null, [handler]);