0

The below code works without issue, it will grab the exact TList i'm looking for. But I have no clue how to iterate it.

What i'm looking for is either how to turn my var dataTableObject into a DataTable or how to iterate the var and then use reflection to grab the specific objects i'm looking for. Meaning my TList has 100 objects, i only want 2 of the objects out of the 100 objects for all my rows.

Assembly assem = Assembly.LoadFrom(Context.Server.MapPath("~/bin/MyApp.Services.dll"));
Type typMyService = assem.GetType(string.Format(
                 "MyApp.Services.{0}Service", pc[i].RadComboBoxDataSourceTable), true);
object oMyService = Activator.CreateInstance(typMyService);
System.Reflection.MethodInfo objMethod = typMyService.GetMethod("GetAll", Type.EmptyTypes);
var dataTableObject = objMethod.Invoke(oMyService, null);

Thanks!

Sergey Litvinov
  • 7,408
  • 5
  • 46
  • 67

1 Answers1

1

If the GetAll result type is DataTable, you can use the direct cast:

DataTable dataTableObject = (DataTable)objMethod.Invoke(oMyService, null);

Using var in this case has no effect, because the compiler do know the method signature and therefore cannot guess the variable type.

Uranus
  • 1,690
  • 1
  • 12
  • 22