dynamic method call

R

RickN

I have some classes set up with the same name as my database tables. I'd
like to be able to access those properties dynamically in a foreach loop wo
having to do a switch case. How do I convert the tablename so it can be
used as a class name?

for example:
DataSet ds;
foreach(DataTable dt in ds.Tables)
{
string s;
string tablename = dt.TableName;
s = mynamespace.tablename.myproperty;
DoSomething(s);
}
Thanks,
RickN
 
V

Vijaye Raji

Reflection is your friend.

Look up on MSDN...

GetType(string)
Type.GetMember(...)

-vJ
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top