Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Generic list question
Message
General information
Forum:
ASP.NET
Category:
Other
Environment versions
Environment:
C# 5.0
OS:
Windows 7
Network:
SAMBA Server
Database:
MS SQL Server
Application:
Desktop
Miscellaneous
Thread ID:
01611163
Message ID:
01611215
Views:
34
>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();
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform