Link to home
Start Free TrialLog in
Avatar of sudgupta
sudgupta

asked on

Quickly Creating Objects in c# at runtime

Hi,
I have a interface

interface IGetData
{
        List<object> getData(string classname);
}

Now my getData needs to get the data from a data source and populate the class object whose class name is "classname".  One of the ways to create the object is to use activator.createInstance. But creating 1 million objects at runtime would mean a lot of performance overhead. Is there a workaround for this problem by using generics etc.
ASKER CERTIFIED SOLUTION
Avatar of ankitkumar29
ankitkumar29
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of multithreading
multithreading

Pass in a fatory object instead of a class name. Use the class name to create the factory object once, then use that object to create objects from the data. The key to using reflection (or activator calls) efficiently is to avoid doing it in tight loops.