Randomly setting up parameter values using reflection

Viewed 42

I have a "Param" object (part of a "module" object) with the "Value" property that can be of any type, such as int, int[], int[,], int[][], etc.

Now, I would like to write a test that randomly populate those parameter values, but I am having the problem that those Values can be of pretty much any type.
Also note that in this application there are many many many parameters, so the way of finding out the Type of each "Value" and how to set it has to be generic. I would think the only approach is to use reflection, but I got stuck pretty quickly as I cannot even find out the size of "Value", which will vary depending on "Value" being either a scalar or an array. Is there a way I could get the size of "Value" as we would normally get from ".Count()" or ".length" using reflection (or other approach)?

So far I am only able to get the type of a given "Value", but that does not give me the size:

var valueType = module.GetPropValue($"{Param.Name}.Value").GetType();

Any suggestion would be very welcome.

0 Answers
Related