Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Generic list question
Message
Information générale
Forum:
ASP.NET
Catégorie:
Autre
Versions des environnements
Environment:
C# 5.0
OS:
Windows 7
Network:
SAMBA Server
Database:
MS SQL Server
Application:
Desktop
Divers
Thread ID:
01611163
Message ID:
01611185
Vues:
51
>I don't think my design is very good, if I spell it out what I'm trying to do you might have a better way of achieving what I'm struggling with, I'm pulling data from several different Excel worksheets using NPOI and then serialising them to a csv file using the class you pointed out a week or so back, all this is working well but I want to tidy it up. At present there are only three different types of imports but I'm sure this will change in the future - so basically I need to build a List for the serialiser of one of three types

Not sure I understand the problem. If all three classes implement ITarriffDataImport why can't you use a non-generic version of XlToList as suggested in my update ? Simply:
public class XlToList
    {
        public List<ITarriffDataImport> Data { get; set; } 
         //etc
    }
and use the linq Cast to populate the Data field. Assuming TDI1 implements ITarriffDataImport:
var theList = new List<TDI1>();
var xlListClass = new XlToList();
xlListClass.Data = theList.Cast<ITarriffDataImport>().ToList();
UPDATE: Actually, if you make the Data field IEnumerable rather than List you don't need to cast ........
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform