What problem do I want to solve? Through reflection, I want to execute code (running instance methods, as well as static methods), where I do not know in advance how the method that will be executed is determined.
Say I have MethodInfoone that I want to call. I do not know what parameters he has, so I do the following.
first, I check that the parameters of the method are valid (if they are not valid, then the method is not called):
private static IEnumerable<Type> GetValidMethodTypes()
{
var validTypes = new List<Type>();
validTypes.AddRange(new[]
{
typeof (SByte),
typeof(String[]),
});
return validTypes;
}
Then I generate random values ββdepending on the type of parameter:
public object RandomizeParamValue(string typeName)
{
switch (typeName)
{
case "SByte":
{
}
case "String[]":
{
}
}
}
, String [] [ "a", "ab", "ccc" ] [ "aa", "b" ]. : [ 1 5], . :)
, , . , . , , . , . - / ?
: , , :
void SomeMethod(unknowntypeatcompiletime param);
unknowntypeatcompiletime .