gpt4 book ai didi

独立;获取方法的参数

转载 作者:行者123 更新时间:2023-12-01 02:30:59 31 4
gpt4 key购买 nike

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

最佳答案

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

System.Windows.Forms.Control.BeginInvoke(Delegate,Object[])

这是它的 Name :
BeginInvoke(Delegate,Object[])

例如,这是一个 CQLinq 规则,它利用参数类型名称来匹配事件处理程序方法:
// <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".

关于独立;获取方法的参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12959396/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com