I have a generic method to deal with importing various object types from Quickbooks.
public ActionConfirmation<int> Import<TEntity>(List<TEntity> lstEntityModifiedSinceLastSync, FinancialsSyncJobQueue currentJobQEntry, FinancialsSyncSession session, 
    FinancialsIntegrationContext financialsIntegrationContext) 
    where TEntity : class, IEntity, IAuditStamps, IFinancials, new()
Today I use a switch statement to invoke the above generic method with the correct type:
switch (enumDataElement)
{
    case DataElement.Account:
        {
            //Parse QB query response and convert to Stratus Chart of Accounts object list
            var lstAccountsModifiedSinceLastSync = QuickbooksChartOfAccounts.ParseQueryResponse(response, session);
            importResult = importService.Import<FinancialsChartOfAccount>(lstAccountsModifiedSinceLastSync, 
                currentJobQEntry, session, financialsIntegrationContext);
            break;
        }
    case DataElement.Item:
        {
            var lstItemsModifiedSinceLastSync = QuickbooksItem.ParseQueryResponse(response, session);
            importResult = importService.Import<Item>(lstItemsModifiedSinceLastSync, 
                currentJobQEntry, session, financialsIntegrationContext);
            break;
        }
        etc...
}
I'd like to clean this up a little, pull the importService.Import call out of the switch statement and put it at the end and do something like:
Type entityType = lstItemsModifiedSinceLastSync.FirstOrDefault().GetType();
importResult = importService.Import<entityType>(lstItemsModifiedSinceLastSync, 
    currentJobQEntry, session, financialsIntegrationContext);
But I can't seem to get that to work. Error is: The type or namespace could not be found...
 
     
    