Reputation: 11765
In my .net windows application(c#) i want know the number of arguments in each constructor of a particular class. I get all the constructor by using reflection. Is it possible to get the number of arguments of each constructors
?
Thanks in advance...
Upvotes: 4
Views: 2997
Reputation: 93030
Type t = typeof(...);
var constructors = t.GetConstructors();
foreach (var con in constructors)
{
Console.WriteLine(con.GetParameters().Length);
}
Upvotes: 5
Reputation: 138051
Ask for its parameters (through GetParameters()), then ask for the length of the array.
ConstructorInfo ctor = /* ... */
int numberOfArguments = ctor.GetParameters().Length;
Upvotes: 8