什么是最有效的方式来问的MethodInfo多少参数需要吗? [英] What is the most efficient way to ask a MethodInfo how many parameters it takes?

查看:328
本文介绍了什么是最有效的方式来问的MethodInfo多少参数需要吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是最有效的方式来问的MethodInfo,如果它接受的参数,如果是这样,有多少?

What is the most efficient way to ask a MethodInfo if it accepts parameters and, if so, how many?

我目前的解决办法是: methodInfo.GetParameters()任何() methodInfo.GetParameters()。COUNT()

My current solutions would be: methodInfo.GetParameters().Any() and methodInfo.GetParameters().Count().

这是最有效的方法是什么?

Is this the most efficient way?

由于我实际上并不需要任何的的ParameterInfo 的对象,是有办法做到这一点没有来电 GetParameters()

Since I don't actually need any of the ParameterInfo objects, is there a way to do this without a call to GetParameters()?

推荐答案

在列出的两个是LINQ。 任何()收益布尔 - 指出,有至少一个。 COUNT()使用了任何关于的IEnumerable< T>

The two you listed are for LINQ. Any() returns bool - stating that there is at least one. Count() is used any on IEnumerable<T>.

长度(属性)将是最快的,因为 GetParameters()收益的ParameterInfo []

Length (the property) will be the fastest because GetParameters() returns ParameterInfo[].

它不会出现的MethodInfo 有任何其他的方式来访问的比<$ C $等参数的数量C> GetParameters()。

It does not appear that MethodInfo have any other way to access the number of parameters other than GetParameters().

这篇关于什么是最有效的方式来问的MethodInfo多少参数需要吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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