Question

How can I, using CQLINQ, get collection of input arguments for current method? There is any collection like "Arguments" or "Parameters" only "NbParamenter" which is not suitable for my purposes.

Était-ce utile?

La solution

Indeed, CQLinq doesn't have this feature yet. However, in many cases you can compensate thanks to the fact that the properties ICodeElement.Name and IMember.FullName, for a IMethod, contain the coma separated list of names of the parameters types. For example here is the FullName of a method:

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

and here is its Name:

BeginInvoke(Delegate,Object[])

Here is for example a CQLinq rule that harnesses parameters types names, to match event handlers methods:

// <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".
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top