Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to differentiate between T and IList<T>

Tags:

c#

generics

I have two methods:

public static int Insert<T>(this System.Data.IDbConnection connection, T param)
public static int Insert<T>(this System.Data.IDbConnection connection, IList<T> param)

When I try something like this:

connection.Insert(new List<Foo>());

the wrong method (first method) is called.

How can I make it work?

like image 705
MuriloKunze Avatar asked Jan 04 '23 05:01

MuriloKunze


1 Answers

If there are generic overloads that can be implicitly called the same way, you have to use an explicit call.

This code will call the second overload.

connection.Insert<Foo>(new List<Foo>());
like image 190
Matt Rowland Avatar answered Jan 06 '23 18:01

Matt Rowland