-
Notifications
You must be signed in to change notification settings - Fork 4
Gendarme.Rules.BadPractice.PreferParamsArrayForVariableArgumentsRule(git)
Assembly: Gendarme.Rules.BadPractice
Version: git
The rule warns for any method that use the (semi-documented) vararg calling convention (e.g. __arglist in C#) and that is not used for interoperability (i.e. pinvoke to unmanaged code). Using params (C#) can to achieve the same objective while vararg is not CLS compliant. The later will limit the usability of the method to CLS compliant language (e.g. Visual Basic does not support vararg.
Bad example:
public void ShowItems_Bad (string header, __arglist)
{
Console.WriteLine (header);
ArgIterator args = new ArgIterator (__arglist);
for (int i = 0; i < args.GetRemainingCount (); i++) {
Console.WriteLine (__refvalue (args.GetNextArg (), string));
}
}
Good example:
public void ShowItems (string header, params string [] items)
{
Console.WriteLine (header);
for (int i = 0; i < items.Length; i++) {
Console.WriteLine (items [i]);
}
}
Good example (interoperability):
[DllImport ("libc.dll")]
static extern int printf (string format, __arglist);
- This rule is available since Gendarme 2.8
You can browse the latest source code of this rule on github.com
Note that this page was autogenerated (3/17/2011 1:55:44 PM) based on the xmldoc
comments inside the rules source code and cannot be edited from this wiki.
Please report any documentation errors, typos or suggestions to the
Gendarme Mailing List. Thanks!