0

How to cast a List of X object, based on the name in string?

I have this case:

public void AssignValue(string className, Dataset.Table table){
    Type currentType = Type.GetType("Namespace." + className);
    var objectCasted = (List<currentType.GetType()>)result;
} 

Then, I'm trying to cast a List of a dynamic object, how I can do it using reflection?

Benjamin RD
  • 11,516
  • 14
  • 87
  • 157

1 Answers1

1

You can't cast to a type that is not known at compile time. Since your object is a List, it implements IList which might be good enough to allow you to access to the methods and properties you need:

Titian Cernicova-Dragomir
  • 230,986
  • 31
  • 415
  • 357