1

Is it possible to overload Extension Methods?

I did something like this

    public static ExcelWorksheet CreateSheet(this ExcelPackage thisPackage, List<Document> list)
    {
        ExcelWorksheet worksheet = thisPackage.Workbook.Worksheets.Add("Documents");
        return worksheet;
    }
    public static ExcelWorksheet CreateSheet(this ExcelWorksheet thisPackage, List<Book> list)
    {
        ExcelWorksheet worksheet = thisPackage.Workbook.Worksheets.Add("Books");
        return worksheet;
    }

In this case, It recognizes only the first method as an extension method and Ignores the second method without any Compiler Warnings or Errors.

Ody
  • 2,012
  • 4
  • 25
  • 35
  • Dupe: http://stackoverflow.com/questions/2118064/extension-methods-overloading-in-c-does-it-work – Charleh Jun 12 '12 at 09:15

1 Answers1

2

You aren't overloading here as the extension methods are on different objects, ExcelPackage and ExcelWorksheet. Overloading extension methods is acceptable though.

Richard
  • 8,110
  • 3
  • 36
  • 59