Skip to content

Commit 351f5a9

Browse files
authored
Update README.md
1 parent 0ae1f8a commit 351f5a9

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ If you're already using the awesome [Dapper ORM](https://github.com/DapperLib/Da
7474

7575
```csharp
7676
// override Dapper extension method to use fast MapDataReader instead of Dapper's built-in reflection
77+
// mind that we use "SqlConnection" here to abuse C# "type specificty", otherwise you get "ambiguous call" compile error
7778
public static List<T> Query<T>(this SqlConnection cn, string sql, object parameters = null)
7879
{
7980
if (typeof(T) == typeof(MyClass)) //our own class that we marked with attribute?
@@ -90,6 +91,8 @@ Why the C# compiler will choose your method over Dapper's?
9091

9192
When the C# compiler sees two extension methods with the same signature, it uses the one that's "closer" to your code. "Closiness" - is determined by multiple factors - same namespace, same assembly, derived class over base class, implementation over interface etc. Adding an override like this will silently switch your existing code from using Dapper/reflection to using our source generator (b/c it uses a more specific connection type and lives in your project's namescape), while still keeping the awesomeness of Dapper and you barely have to rewrite any of your code.
9293

94+
Mind that we use "SqlConnection" for the extension method here to abuse C# "type specificty", otherwise you get "ambiguous call" compile error.
95+
9396
---
9497

9598
## P.S. But what's the point?

0 commit comments

Comments
 (0)