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:
01611215
Vues:
33
>Hi Viv, I still have one problem remaining, my code has references to T in several places, e.g. when adding to my list I use stuff like
>
>
>If(T == type of(MyClass))
>{
>This.Data.Add( new T()
>{
>// and depending on my class I populate different properties here.
>});
>else
>{
>   // and so on
>}
>
>
If you're not using generics would something like this work:
public class XlToList
    {
        private readonly Type _t; 

        public XlToList(Type t)
        {
            _t = t;
            Data = new List<ITarriffDataImport>();
        }

        public List<ITarriffDataImport> Data { get; set; }

        public void Process()
        {
            Data.Add((ITarriffDataImport)  Activator.CreateInstance(_t));
        }
  }
    
//With:
        var xlListClass = new XlToList(typeof(MyClass));
        xlListClass.Process();
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform