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.
sudguptaAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ankitkumar29Commented:
Have a look at the code here
http://whizzodev.blogspot.com/2008/03/object-cloning-using-il-in-c.html

This is for cloning an object which including creating loads of objects as well as copying value in all of those. You can remove the part of the code which deals with cloning the elements.

Some explanation from that URL itself
The basic thing that it does is, create a DynamicMethod, get the  ILGenerator, emit code in the method, compile it to a delegate, and  execute the delegate.
The delegate is cached so that the IL is not  generated each time a cloning should take place, so we loose only one  time performance, when the first object is cloned (the IL has to be  created and compiled at runtime).

You will also have to consider if your datasource will be a bottleneck in the speed of creation of objects and you might have to try using threads for that.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
multithreadingCommented:
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.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.