Link to home
Create AccountLog in
Avatar of bemara57
bemara57

asked on

How do I invoke methods dynamically (reflection?)

I'm trying to accomplish something and I can't quite understand the concept of reflection to even know if that's the answer- or maybe anonymous methods?? Not sure, but what I'm trying to do is pass in a method into another method, so the 'parameter' method can perform tasks inside the parent method.. Here's an example of what I'm trying to do:

public object GetItem(method ObjectWrapper)
{
      OleDbCommand cmd = new OleDbCommand(sqlCmd, conn);
      conn.Open();
      return ObjectWrapper(cmd.ExecuteReader());
}

...

public static ItemCollection ItemsHolder(IDataReader reader)
{
     ItemCollection allItems = new ItemCollection();
     while (reader.Read())
     {
           Item newItem = new Item();
           newItem.Sku = reader["sku"];
           ...
           allItems.Add(newItem);
     }
     return allItems;
}

So in my implementation class, I just want to be able to go like this:
GetItem(ItemsHolder);

Does that make sense? Is it possible?

ASKER CERTIFIED SOLUTION
Avatar of ZachSmith
ZachSmith
Flag of United States of America image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account