Reputation: 838
Scenario: I have App.Config file in which there are certain methods and I want to call them through Reflection. While doing this I also need to tell the Type of parameters being passed to that method. I'm retrieving the list of parameter types of that method at runtime like this:
ParameterInfo[] parameters = magicType.GetMethod("ItsMagic").GetParameters();
But I don't know how to put this array in following function:
magicType.GetMethod("ItsMagic", new Type[] {parameters.Cast<Type>()});
It results in following error:
Error: Cannot implicitly convert type 'System.Collections.Generic.IEnumerable' to 'System.Type'. An explicit conversion exists (are you missing a cast?)
Any suggestions how to achieve that?
Upvotes: 0
Views: 298
Reputation: 116178
parameters.Select(p=>p.ParameterType).ToArray()
magicType.GetMethod("ItsMagic", parameters.Select(p=>p.ParameterType).ToArray() );
Upvotes: 2