如何使用CQLINQ获取当前方法的输入参数集合?有任何像“参数”或“参数”这样的集合,只有"NbParamenter“,这不适合我的目的。
发布于 2012-10-19 15:29:45
实际上,CQLinq还没有这个特性。但是,在许多情况下,您可以进行补偿,因为对于IMethod,属性ICodeElement.Name和IMember.FullName包含参数类型的名称的逗号分隔列表。例如,下面是一个方法的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".https://stackoverflow.com/questions/12959396
复制相似问题