I have the following method:
private static object[] GenerateParameters(MethodBase executingMethod)
{
var parameterInfoList = MethodBase.GetCurrentMethod().GetParameters();
var parameterObjectList = new List<object>();
for (var i = 0; i < parameterInfoList.Count(); i++)
{
parameterObjectList.Add(parameterInfoList.GetValue(i));
}
return parameterObjectList.ToArray();
}
It just seems to me that is is bloated and over complicated. Is there a way to turn this method into one or two lines of code that will do the same thing? Possibly using Lambda or LINQ.
The reason why I think it is so bloated is because you can only get the value of the parameters from a parameterInfo array and not each parameterInfo (parameterInfo has no GetValue). There has to be a better way to do this.
EDIT
There was A LOT of great answers, and each of them worked, so thank you to everyone.
Check this