首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >N依赖;获取方法的参数

N依赖;获取方法的参数
EN

Stack Overflow用户
提问于 2012-10-19 00:32:18
回答 1查看 694关注 0票数 4

如何使用CQLINQ获取当前方法的输入参数集合?有任何像“参数”或“参数”这样的集合,只有"NbParamenter“,这不适合我的目的。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2012-10-19 15:29:45

实际上,CQLinq还没有这个特性。但是,在许多情况下,您可以进行补偿,因为对于IMethod,属性ICodeElement.NameIMember.FullName包含参数类型的名称的逗号分隔列表。例如,下面是一个方法的FullName

代码语言:javascript
复制
System.Windows.Forms.Control.BeginInvoke(Delegate,Object[])

这是它的Name

代码语言:javascript
复制
BeginInvoke(Delegate,Object[])

下面是一个利用参数类型名称来匹配事件处理程序方法的CQLinq规则:

代码语言:javascript
复制
// <Name>Event handler methods should be declared private</Name>
warnif count > 0
from m in Application.Methods where 
  !m.IsPrivate &&

   // A method is considered as event handler if...
   m.NbParameters == 2 &&            // ...it has two parameters..
   m.Name.Contains("Object") &&    // ...of types Object...
   m.Name.Contains("EventArgs") && // ...and EventArgs

   // Discard special cases
  !m.ParentType.IsDelegate &&
  !m.IsGeneratedByCompiler

select new { m,m.Visibility }
// This rule implementation relies on the facts that:
// -> A method name contains the type of its parameters.
// -> All EventArgs derived types have the suffix "EventArgs".
票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/12959396

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档