Im trying to write a small framework for REST-API testing. Im using a lot of reflection and came to a problem I cant help myself.
Im using this line to extract a variable the user gives my as a path (string)
object o = input.GetType().GetProperty(name).propertyInfo.GetValue(input, null);
This object can be a normal type T or a List<T>.
Now if its a List and I know the type everything is simple, I can use
List<string> l = (List<string>)o; // I know its a List<string> because the user told me
To parse the object into the given array. But I dont always know the type of the objects in the list and
List<object> l = (List<object>)o; // I dont know the type and I dont care
gives me an error.
Object of type "System.Collection.GenericList[System.String]" can not be converted to "System.Collection.GenericList[System.Object]"
Is there anything I can do to receive the list of objects? I dont want the user to specify the type because its only the last variable I want to care about. Like
The user wants to test "object1.a.b.c" I only need to know the type of c, because thats where the test runs.
TIA
dynamic? Ed: you mention specifically that you "don't know... don't care" about the type, hence why I ask about dynamictest<myClass>("a.b.c", x => x.foo() > 5); // c is of type myClass