如何获取构造函数中的参数数量 [英] How to get number of arguments in a constructor

查看:22
本文介绍了如何获取构造函数中的参数数量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的 .net windows 应用程序 (c#) 中,我想知道特定类的每个构造函数中的参数数量.我通过使用反射获得所有构造函数.是否可以获取每个构造函数的参数个数?

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?

提前致谢...

推荐答案

询问其参数(通过 GetParameters()),然后询问数组的长度.

Ask for its parameters (through GetParameters()), then ask for the length of the array.

ConstructorInfo ctor = /* ... */
int numberOfArguments = ctor.GetParameters().Length;

这篇关于如何获取构造函数中的参数数量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆