Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Help with generic
Message
From
18/07/2007 11:13:50
 
 
To
18/07/2007 10:49:12
Victor Acosta
Independent Programmer.
San José, Costa Rica
General information
Forum:
ASP.NET
Category:
Coding, syntax and commands
Environment versions
Environment:
C# 2.0
OS:
Windows Server 2003
Network:
Windows 2003 Server
Database:
MS SQL Server
Miscellaneous
Thread ID:
01241343
Message ID:
01241562
Views:
21
>I can not create a Conditional as a CASE, IF or similar because, YES, I have 600 different objects, each table of my system represents a new object.
>
>So I will have something like this:
>
>Webpage1
>RegionCollection myregioncollection = new RegionCollection().Load();
>. . . //more code
>Webpage2
>EmployeeCollection myregioncollection = new employeCollection().Load();
>
>Other webpage to N
>AuthorCollection myregioncollection = new AuthorCollection().Load();
>
>
>So, you could have as many objects as you pages you need to perform CRUD operations.
>
>
>Now to make life easier, I am creating a web control that allows to navigate through the data (move first, move last, delete, new, etc).
>
>
>I need to recover the object from the session in the web control:
>
>
>Xtype myLOCALcollection;
>myLOCALcollection = (Xtype) Session["coleccion"];
>
>
>Here you can see my trouble, I don’t know at compile time, what is the type of the local collection, say, the current collection.
>
>In few words, I need to create the type Xtype at run-time and BASED on the type of the object that is saved into the session var.


Hi, Victor.

As I said, I guess it is a design problem. What do you want to do with the objects in the collection? If what you need is to perform CRUD operations, then your objects should all implement a common interface like: IPersistent or something like that (with New, Save and Delete operations, for example:

In this case, when you loop through your collection you use:


for each ( IPeristent entity in yourCollection )
entity.Save();


Do you understand the general idea? Of course this could be safer using generics, but it works like that with your code.


Regards,
Previous
Reply
Map
View

Click here to load this message in the networking platform