Using 'dynamic' to save lines I am pushing an Excel file to the server and then reading it's contents. XLS and XLSX files need to be read differently, but the DLL that I'm using has the EXACT same function calls for both types. If I use a 'dynamic' type, I can save a lot of lines of code and avoid redundancy. However, I've been told many times before to avoid using dynamic if possible. Is this a good place to use it?

dynamic excelFile; // is this a good use of dynamic?
switch (fileExtension)
{
    case "xls":
        excelFile = new Excel2007();
        break;
    case "xlsx":
        excelFile = new Excel();
        break;
    default:
        results.Message = string.Format("{0} is of an unrecognized format.", uploadFile.FileName);
        return RedirectToAction("ImportWizard");
}

excelFile.OpenDatabase(targetPath, new FieldData());
excelFile.CurrentTable = excelFile.Tables[0];

var excelRecords = excelFile.ReadRecords(100);
excelFile.CloseDatabase();
The prevalent answer is: No. (Funny enough, working with Office files seems to be a valid exception to the rule).

The problem is that you don't have type validation anymore, and any issues will reveal themselves at run time.

I'd say, if it's a small thing and it won't be touched or changed by people who might not know how it works, go for it (Even then, make sure you document this).

Otherwise, an Interface approach sounds like a better idea, like ChrisWue's comment said.